How to Create a Responsive Comment Box Using HTML and CSS


By Faraz -

Learn how to design a comment box using HTML and CSS in this step-by-step tutorial for beginners. Create a responsive comment box that can be added to any webpage.

how to create a responsive comment box using html and css.jpg

Table of Contents

  1. Project Introduction
  2. HTML Code
  3. CSS Code
  4. Preview
  5. Conclusion

Creating a comment box is an essential feature on any website that allows users to provide feedback or comments. In this tutorial, we will teach you how to design a comment box using HTML and CSS, which are fundamental skills for web development. This tutorial is aimed at beginners who have basic knowledge of HTML and CSS and want to practice their skills.

HTML is a markup language used to create the structure of a webpage, while CSS is used to style and design the webpage. By the end of this tutorial, you will have a practical exercise to create a responsive comment box that can be added to any webpage.

We will guide you through the steps required to create a comment box, starting with the HTML structure and then adding CSS styling. We will cover topics such as adding input fields, creating a Submit button, and making the comment box responsive using media queries.

This tutorial assumes that you have a basic understanding of HTML and CSS, and we will write it in a step-by-step format. We will include screenshots to illustrate each step, and we hope that by the end of this tutorial, you will have a good understanding of how to design a comment box using HTML and CSS.

Let's start making a responsive comment box using HTML, and CSS step by step.

Join My Telegram Channel to Download the Projects Source Code: Click Here

Source Code

Step 1 (HTML Code):

To get started, we will first need to create a basic HTML file. In this file, we will include the main structure for our comment box.

After creating the files just paste the following below codes into your file. Make sure to save your HTML document with a .html extension, so that it can be properly viewed in a web browser.

The code starts by defining the document type as HTML and setting the language of the page to English.

The head section of the code contains the title of the page, which is "Comment Box". It also includes some meta information, such as the character encoding used in the page (UTF-8) and the width of the viewport.

The code then defines a link to an external stylesheet named "styles.css". This file is used to style the HTML elements in the page.

The body section of the code contains a container div that holds the comment box section. The comment box section is defined as a div element with the class "comment-box" and a gradient background color.

Inside the comment box, there is a heading element (h2) with the class "comment-title" that displays the text "Join the conversation". Below the heading, there is a form element that contains three form groups.

Each form group has a label element that describes the purpose of the input field, such as "Name" or "Email". The input fields themselves are defined as input elements with the type "text" and "email", respectively. There is also a textarea element with the name "comment" that allows the user to enter a comment.

Finally, the code includes a submit button that sends the form data to the server for processing when clicked. This button is defined as a button element with the class "btn-submit".

This is the basic structure of our comment box using HTML, and now we can move on to styling it using CSS.

Step 2 (CSS Code):

Once the basic HTML structure of the comment box is in place, the next step is to add styling to the comment box using CSS.

Next, we will create our CSS file. In this file, we will use some basic CSS rules to style our comment box.

The code starts with the body element which sets the background color of the page to a light blue shade.

The container element is then defined, which sets the maximum width of the comment box section to 600 pixels and centers it horizontally using the margin property.

The comment-box element is styled to have a white background, padding of 40 pixels, rounded corners of 10 pixels, and a box shadow effect. This creates a container with a clean and modern look.

The comment-title element is styled with a large font size of 36 pixels, centered text, a margin bottom of 30 pixels, and a white text color.

The form-group elements are styled to have a margin bottom of 20 pixels. The label elements inside them have a bold font weight, a font size of 18 pixels, and a white text color.

The input fields and textarea elements are styled to have a width of 100%, a padding of 10 pixels, rounded corners of 5 pixels, no border, and a transition effect that changes the background color when the user interacts with them. The background color is set to a light gray shade with a font color of dark gray.

The submit button is styled with a dark blue background color, white text color, a padding of 10 pixels horizontally and 20 pixels vertically, rounded corners of 5 pixels, a font size of 18 pixels, and a cursor that changes to a pointer on hover. The transition effect changes the background color on hover to a darker shade of blue.

The gradient-bg class is used to create a gradient background effect that goes from a dark blue (#003366) at the top to a lighter blue (#005aaa) at the bottom. The submit button inside this class has a white background color, dark blue text color, and a 2-pixel solid white border. The transition effect changes the background and text colors on hover.

This will give our comment box an upgraded presentation. Create a CSS file with the name of styles.css and paste the given codes into your CSS file. Remember that you must create a file with the .css extension.

  background-color: #dfecf7;

  max-width: 600px;
  margin: 0 auto;

.comment-box {
  background-color: #fff;
  padding: 40px;
  border-radius: 10px;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);

.comment-title {
  font-size: 36px;
  text-align: center;
  margin-bottom: 30px;
  color: #fff;

.form-group {
  margin-bottom: 20px;

.form-group label {
  display: block;
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 5px;
  color: #fff;

.form-group input[type="text"],
.form-group input[type="email"],
.form-group textarea {
  width: 100%;
  padding: 10px;
  border-radius: 5px;
  border: none;
  font-size: 16px;
  transition: background-color 0.3s;
  background-color: #f2f2f2;
  color: #333;

.form-group input[type="text"]:focus,
.form-group input[type="email"]:focus,
.form-group textarea:focus {
  background-color: #fff;

.btn-submit {
  background-color: #005aaa;
  color: #fff;
  padding: 10px 20px;
  border: none;
  border-radius: 5px;
  font-size: 18px;
  cursor: pointer;
  transition: background-color 0.3s;

.btn-submit:hover {
  background-color: #003366;

.gradient-bg {
  background: linear-gradient(to bottom, #003366, #005aaa);

.gradient-bg .btn-submit {
  background-color: #fff;
  color: #005aaa;
  border: 2px solid #fff;
  transition: background-color 0.3s, color 0.3s;

.gradient-bg .btn-submit:hover {
  background-color: #005aaa;
  color: #fff;

Final Output:

how to create a responsive comment box using html and css.gif

See the Pen Responsive Comment Box by Faraz (@codewithfaraz) on CodePen.


In conclusion, we have learned how to create a comment box using HTML and CSS. By following the step-by-step guide, you should now be able to create a responsive comment box that can be added to any webpage.

HTML and CSS are essential skills for web development, and this tutorial has given you a practical exercise to practice those skills. We have covered topics such as creating the HTML structure, adding input fields, styling the comment box using CSS, creating a Submit button, and making the comment box responsive using media queries.

Remember, a good user experience is essential for any website, and a well-designed comment box is one way to improve user engagement. By implementing what you have learned in this tutorial, you can create a more interactive and engaging website for your users.

We hope that you found this tutorial helpful, and we encourage you to continue practicing your HTML and CSS skills. With time and practice, you can become a proficient web developer and create beautiful and functional websites.

That’s a wrap!

I hope you enjoyed this post. Now, with these examples, you can create your own amazing page.

Did you like it? Let me know in the comments below 🔥 and you can support me by buying me a coffee.

And don’t forget to sign up to our email newsletter so you can get useful content like this sent right to your inbox!

Faraz 😊

End of the article

Subscribe to my Newsletter

Get the latest posts delivered right to your inbox

Latest Post