How To Box In Html

Boxes are everywhere on the web, and they make the foundation of a website’s layout. They contain elements like text, images, or other boxes, and they help to organize content visually. In this tutorial, we will learn how to create boxes in HTML (using div tags), and style them using CSS.

Creating a Box in HTML

To create a box in HTML, we will use the <div> element. The <div> element is a block-level container that can be styled using CSS. It doesn’t have any default style, which makes it perfect for our purpose. Here’s an example of a simple HTML box:

      This is a box.

However, this box won’t look any different from regular text, as it has no styles applied yet. Let’s now use CSS to style our box.

Styling a Box with CSS

To style our box, we need to use CSS. CSS stands for Cascading Style Sheets, and it is a language that allows you to apply styles to HTML elements. There are multiple ways to apply CSS to your HTML code, but we will use the <style> tag in the head section of our HTML file for this tutorial.

Here’s an example of how to apply some basic styles to our box:

        .box {
            width: 300px;
            height: 200px;
            background-color: lightblue;
            border: 2px solid black;
            padding: 20px;
            margin: 10px;

In this example, we’ve created a class called .box and applied some basic styles to it, such as width, height, background color, border, padding, and margin. Now, to apply these styles to our div, we need to add the class attribute to the div element, like this:

    &lt;div class="box"&gt;
      This is a styled box.

And that’s it! Now you have a simple, styled HTML box. You can further customize the box by modifying the CSS properties or adding new ones. Experiment with different styles to create unique boxes for your website.


In this tutorial, we’ve learned how to create and style boxes in HTML using div elements and CSS. Now you can use these techniques to create visually appealing layouts and organize content on your website. Keep practicing and experimenting with different styles to enhance your web design skills!