Introduction to <!doctype>tag

The <!doctype>declaration in HTML, often referred to as the <DOCTYPE>tag, is an essential component that specifies the document type and version of HTML being used in a webpage. Although it's not an <HTML>tag itself, it is a declaration that appears at the very beginning of an HTML document. Its primary purpose is to inform the web browser about the version of HTML the page is written in, ensuring that the browser renders the content correctly.

Importance of the <¡doctype>Declaration

Document Type Specification: The <¡doctype>declaration tells the web browser the type of HTML used, such as <HTML5>, <HTML 4.01>, or XHTML. Each version of HTML has its own rules and structures, and the declaration ensures that the browser interprets the document accordingly.

Browser Rendering Mode: The <¡doctype>declaration also influences how browsers render the page. When a valid <¡doctype>is specified, most browsers operate in <standards mode>, which adheres to the W3C (<World Wide Web Consortium>) standards for HTML and CSS. Without it, browsers may enter <quirks mode>, which emulates the non-standard behavior of older browsers, potentially leading to inconsistent page rendering across different browsers.

HTML5 and Modern Web Development: In HTML5, the <¡doctype>declaration is simplified to just <¡doctype html>. This simple declaration is all that's needed to specify that the document is written in HTML5, the latest version of HTML. HTML5 provides new elements, <attributes>, and behaviors that are more in line with modern web development practices, including support for multimedia, graphics, and complex user interactions without the need for external plugins.

Copy to clipboard
<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>title of <!doctype> tag</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<div class="container">
  <h1>LL</h1>
  <nav>
      <ul>
          <li><a href="#home">Home</a></li>
          <li><a href="#about">About</a></li>
          <li><a href="#contact">Contact</a></li>
      </ul>
  </nav>
</div>
</header>

<main>
<section id="home" class="card">
  <h2>Home</h2>
  <p>This is the home section of the webpage. Here you can add some welcome text or a brief introduction about the site.</p>
</section>

<section id="about" class="card">
  <h2>About</h2>
  <p>This is the about section. You can provide some information about yourself or the purpose of the website.</p>
</section>

<section id="contact" class="card">
  <h2>Contact</h2>
  <p>This is the contact section. Add your contact details or a form here.</p>
</section>
</main>

<footer>
<p>&copy; 2024 My Enhanced Webpage. All rights reserved.</p>
</footer>
</body>
</html>
Copy to clipboard
/* Reset some default browser styles */
    body, h1, h2, p, ul {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }
    
    body {
        font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        line-height: 1.6;
        background: linear-gradient(to right, #4facfe, #00f2fe);
        color: #333;
        padding-top: 80px; /* Space for sticky header */
    }
    
    /* Header styles */
    header {
        background-color: rgba(0, 0, 0, 0.8);
        color: #fff;
        padding: 10px 0;
        position: fixed;
        width: 100%;
        top: 0;
        left: 0;
        z-index: 1000;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    }
    
    header .container {
        width: 90%;
        max-width: 1200px;
        margin: 0 auto;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    
    nav ul {
        list-style: none;
        display: flex;
    }
    
    nav ul li {
        margin: 0 15px;
    }
    
    nav ul li a {
        color: #fff;
        text-decoration: none;
        font-weight: bold;
        padding: 5px 10px;
        border-radius: 4px;
        transition: background-color 0.3s ease;
    }
    
    nav ul li a:hover {
        background-color: #4facfe;
    }
    
    /* Main content styles */
    main {
        padding: 20px;
        max-width: 1200px;
        margin: 0 auto;
    }
    
    .card {
        background-color: #fff;
        border-radius: 8px;
        padding: 20px;
        margin-bottom: 20px;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        transition: transform 0.3s ease, box-shadow 0.3s ease;
    }
    
    .card:hover {
        transform: translateY(-5px);
        box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
    }
    
    /* Section styles */
    section h2 {
        margin-bottom: 10px;
        font-size: 1.5rem;
        color: #333;
    }
    
    section p {
        font-size: 1rem;
        color: #666;
    }
    
    /* Footer styles */
    footer {
        background-color: rgba(0, 0, 0, 0.8);
        color: #fff;
        text-align: center;
        padding: 15px 0;
        position: relative;
        width: 100%;
        bottom: 0;
        margin-top: 40px;
        box-shadow: 0 -4px 6px rgba(0, 0, 0, 0.1);
    }
    
    /* Media queries for responsiveness */
    @media (max-width: 768px) {
        header .container {
            flex-direction: column;
            text-align: center;
        }
    
        nav ul {
            flex-direction: column;
            margin-top: 10px;
        }
    
        nav ul li {
            margin-bottom: 10px;
        }
    
        main {
            padding: 10px;
        }
    
        .card {
            padding: 15px;
        }
    }

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
<!DOCTYPE>YesYesYesYesYes