Introduction to <div>tag

The <div>tag in HTML, short for "division," is a versatile and commonly used element for grouping content on a webpage. It serves as a container that allows developers to organize and structure their HTML documents, making it easier to apply styles and manage content dynamically.

Copy to clipboard
<!DOCTYPE html>
<htmllang="en">
<head>
<metacharset="UTF-8">
<metaname="viewport"content="width=device-width, initial-scale=1.0">
<title>title of <div> tag</title>
</head>
<body>
<divclass="container"data-info="Container: Main wrapper of the page">
<!-- Header Section -->
<divclass="header"data-info="Header: Website header area"> <h1>Website Header</h1>
</div> <!-- Main Content Section -->
<divclass="main-content clearfix"data-info="Main Content: Contains sidebar and main content"> <!-- Sidebar Section --> <divclass="sidebar"data-info="Sidebar: Sidebar area"> <h2>Sidebar</h2> <p>This is the sidebar content.</p> </div> <!-- Content Section --> <divclass="content"data-info="Content: Main content area"> <h2>Main Content</h2> <p>This is the main content area.</p> </div>
</div> <!-- Footer Section -->
<divclass="footer"data-info="Footer: Website footer area"> <p>Website Footer</p>
</div>
</div>
</body>
</html>
Copy to clipboard
body {
        font-family: Arial, sans-serif;
        margin: 0;
        padding: 0;
        background-color: #f4f4f4;
    }
    
    .container {
        width: 80%;
        margin: 0 auto;
        padding: 20px;
        border: 2px solid #000; /* Outline for container */
        background-color: #fff;
        position: relative; /* For positioning hover information */
    }
    
    .header, .footer {
        background-color: #e2e2e2;
        text-align: center;
        padding: 15px 0;
        border: 1px solid #000; /* Outline for header and footer */
        margin-bottom: 20px;
        position: relative; /* For positioning hover information */
    }
    
    .main-content {
        margin-bottom: 20px;
        border: 1px solid #000; /* Outline for main content */
        padding: 10px;
        position: relative; /* For positioning hover information */
    }
    
    .sidebar {
        float: right;
        width: 30%;
        padding: 10px;
        background-color: #d9edf7;
        border: 1px dashed #000; /* Dashed outline for sidebar */
        position: relative; /* For positioning hover information */
    }
    
    .content {
        width: 65%;
        float: left;
        padding: 10px;
        background-color: #f5f5f5;
        border: 1px dashed #000; /* Dashed outline for main content */
        position: relative; /* For positioning hover information */
    }
    
    /* Tooltip Styling */
    .header:hover::after, 
    .footer:hover::after, 
    .main-content:hover::after, 
    .sidebar:hover::after, 
    .content:hover::after, 
    .container:hover::after {
        content: attr(data-info); /* Get the data-info attribute */
        position: absolute;
        top: -30px; /* Position above the hovered element */
        left: 50%;
        transform: translateX(-50%);
        background-color: #333;
        color: #fff;
        padding: 5px 10px;
        border-radius: 5px;
        font-size: 12px;
        white-space: nowrap; /* Prevent text from wrapping */
        opacity: 0;
        transition: opacity 0.3s; /* Smooth transition for appearance */
        pointer-events: none; /* Prevent mouse events on tooltip */
    }
    
    /* Show tooltip on hover */
    .header:hover::after, 
    .footer:hover::after, 
    .main-content:hover::after, 
    .sidebar:hover::after, 
    .content:hover::after, 
    .container:hover::after {
        opacity: 1; /* Show tooltip */
    }
    
    .clearfix::after {
        content: "";
        display: table;
        clear: both;
    }

Global Attributes

AttributesDescription
accesskeySpecifies a shortcut key to activate or focus an element.
autocapitalizeControls whether and how text input is automatically capitalized.
classSpecifies one or more class names for the element, allowing CSS styling and JavaScript manipulation.
contenteditableSpecifies whether the content of an element is editable or not.
contextmenuSpecifies a context menu for the element.
dirDefines the text direction. Possible values are "ltr" (left-to-right), "rtl" (right-to-left), and "auto".
draggableSpecifies whether an element is draggable. Possible values are "true" or "false".
enterkeyhintSpecifies the action label or icon to be shown for the enter key on virtual keyboards.
hiddenIndicates that the element is not yet, or is no longer, relevant. The browser does not display elements that have the `hidden` attribute set.
idSpecifies a unique identifier for the element.
inputmodeProvides a hint to browsers for which virtual keyboard configuration to use when editing this element or its descendants.
isAllows you to specify the type of custom element.
langSpecifies the language of the element's content.
nonceA cryptographic nonce ("number used once") that can be used by Content Security Policy (CSP) to determine whether or not a given fetch will be allowed to proceed.
partSpecifies the element’s part in the shadow DOM.
slotAssigns a slot in a shadow DOM shadow tree.
spellcheckIndicates whether the element is subject to spell checking.
styleProvides inline CSS styling for the element.
tabindexSpecifies the tab order of the element.
titleAdds extra information about the element, displayed as a tooltip when hovering over the element.
translateSpecifies whether the content of the element should be translated. Possible values are "yes" or "no".
HTML AttributesGlobal AttributesEvent Attributes
To view the full list
To view the full list
To view the full list
elementsChrome BrowsersMicrosoft Edge BrowserFirefox BrowsersSafari BrowserOpera Browser
<div>YesYesYesYesYes