Category: Basic

  • Images

    HTML images provide visual content for web pages, enhancing user experiences and conveying information. They can be photographs, graphics, icons, or illustrations.

    HTML offers various elements for embedding, manipulating, and controlling images, contributing to the aesthetics and functionality of websites. Understanding image tags, attributes, and responsive design principles is essential for effective web development.

    HTML Images

    HTML Image Syntax

    The following is the basic syntax for HTML images:

    <img src="image_path" alt="Alternate text for the image" width="200px" height="150px" />

    Here,

    • src: The src attribute defines the path of the image (image URL).
    • alt: The alt attribute defines the alternate text; if there is a broken link to the image path, the alternate text displays on the webpage.
    • width and height: The width and height attribute define the height and width for the image.

    Insert Image

    You can insert (embed) an image on the webpage using the <img> tag with the src attribute, which is a required attribute to define the image path.

    Note: The <img> tag is an empty tag, which means that it can contain only a list of attributes and has no closing tag.

    Syntax

    Use the following syntax to insert an image using the <img> tag:

    <img src="Image URL" ... attributes-list/>

    Example

    To try the following example, let’s keep our HTML file test.htm and image file test.png in the same directory −

    <DOCTYPE html><html><head><title>Example of HTML Image (Insert on the webpage)</title></head><body><h1>Example of HTML Image (Insert on the webpage)</h1><img src="/html/images/test.png" alt="Test Image" /></body></html>

    You can use PNG, JPEG, or GIF image files based on your comfort, but make sure you specify the correct image file name in the src attribute. The image name is always case-sensitive.

    The alt attribute is an optional attribute but recommended as it specifies an alternate text for an image if the image cannot be displayed.

    Set Image Location

    Image location (path) must be clearly defined in the src attribute. You can follow the absolute path, which starts with root directory (/), then directory name (if any), and then image name with its extension.

    Example

    For example, if we have an image named “test.png” and it is stored in the “images” folder, which is in the “html” folder on the root directory. You can simply use an image path like “/html/images/test.png“.

    <!DOCTYPE html><html><head><title>Using Image in Webpage</title></head><body><img src="/html/images/test.png" alt="Test Image" /></body></html>

    Set Image Width and Height

    You can set image width and height based on your requirements using width and height attributes. You can specify the width and height of the image in terms of either pixels or a percentage of its actual size.

    Example

    The following example demonstrates how to set the width and height of an image:

    <!DOCTYPE html><html><head><title>Set Image Width and Height</title></head><body><p>Setting image width and height</p><img src="/html/images/test.png" alt="Test Image" width="450px" height="200px" /></body></html>

    Bordered Image

    You can specify the border and its thickness in terms of pixels using the border attribute. A thickness of 0 means there is no border around the picture.

    Example

    In the following example, we are specifying a border on an image:

    <!DOCTYPE html><html><head><title>Set Image Border</title></head><body><p>Setting image Border</p><img src="/html/images/test.png" alt="Test Image" border="3" /></body></html>

    Image Alignment

    By default, the image will align at the left side of the page, but you can use the align attribute to set it in the center or right.

    Example

    In the following example, we are specifying right align to an image:

    <!DOCTYPE html><html><head><title>Set Image Alignment</title></head><body><p>Setting image Alignment</p><img src="/html/images/test.png" alt="Test Image" border="3" align="right" /></body></html>

    Animated Images

    You can also use animated images (having .gif extensions) on the webpages. There is no specific attribute required to show animated images; you can simply set the path of the animated image (.gif) in the src attribute.

    Animated Image

    Example

    The following example demonstrates how you can insert an animated image:

    <!DOCTYPE html><html><head><title>Using Animated Images in HTML</title></head><body><h1>Using Animated Images in HTML</h1><img src="/html/images/animated_image.gif" alt="Animated Images"  /></body></html>

    Responsive Images

    You can also make the images responsive, which will automatically adjust their size based on the devices screen size and resolution. The following are the methods to make images responsive:

    1. Using CSS

    Using CSS, you can set the width of the image to 100%, which allows the image to scale proportionally to its parent container.

    <img src="/html/images/test.png" alt="Responsive Image" style="width: 100%; height: auto;"/>

    2. Using the <picture> Tag

    You can also display different images in different sizes or resolutions by using the <picture> tag, which is useful when you want to display different images based on the device.

    <picture><source media="(min-width: 800px)" srcset="image_path_1"><source media="(max-width: 799px)" srcset="image_path_2"><img src="default_image_path.jpg" alt="Responsive Image"></picture>

    Example

    The following example demonstrates how you can define a responsive image to display on the webpage:

    <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Responsive Image Example</title><style>
    
        img {
            width: 100%;
            height: auto;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;Responsive Image Example&lt;/h1&gt;&lt;img src="/html/images/test.png" alt="A responsive example image" /&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Supported Image Formats

    The following table shows the supported image formats in the HTML <img> tag:

    Image FormatImage Format NameTransparency SupportAnimation SupportFile Extensions
    JPEG/JPGJoint Photographic Experts GroupNoNo.jpg, .jpeg
    PNGPortable Network GraphicsYesNo.png
    GIFGraphics Interchange FormatYesYes.gif
    SVGScalable Vector GraphicsYesNo.svg
    WebPWeb Picture formatYesYes.webp
    BMPBitmap Image FileNoNo.bmp
    ICOIcon FileYesNo.ico

  •  Colors

    HTML colors are a way of specifying the appearance of web elements. They are very important aspects of web design, as they not only enhance the visual appeal but also influence user behavior. They are also used to evoke emotions and highlight important content.

    In HTML, colors are generally defined for backgrounds, borders, and texts. To specify the colors, the style attribute of HTML elements is used.

    HTML Color Coding Methods

    The following three methods are used to set colors in a web page −

    • Color names − We can specify color names directly, like green, blue, or red.
    • Hex codes − A six-digit code representing the amount of red, green, and blue that makes up the color.
    • Color decimal or percentage values − This value is specified using the rgb() property.

    We will learn these color coding methods in upcoming chapters.

    HTML Color Names

    We can specify a direct color name to set text or background color. W3C has listed 16 basic color names that will validate with an HTML validator, but there are over 200 different color names supported by major browsers.

    Find the full list of the supported color names in HTML:HTML Color Names

    W3C Standard 16 Colors

    The following are the W3C standard color names that are supported by all browsers:

    BlackGraySilverWhite
    YellowLimeAquaFuchsia
    RedGreenBluePurple
    MaroonOliveNavyTeal

    Example

    Here is an example showing how you can use the color names in an HTML document:

    <!DOCTYPE html><html><head><title>HTML Colors by Name</title></head><body text="blue" bgcolor="green"><p>Use different color names for for body and table and see the result.</p><table bgcolor="black"><tr><td><font color="white">This text will appear white on black background.</font></td></tr></table></body></html>

    Browser Safe Colors

    Colors can also be specified using the web-safe colors, which are formed by the combination of red, green, and blue (RGB) hex values.

    Here is a list of 216 colors that are considered the safest and most consistent across different computers. These colors range from the hexadecimal code #000000 (black) to #FFFFFF (white) and are supported by all computers using a 256-color palette.

    0000000000330000660000990000CC0000FF
    0033000033330033660033990033CC0033FF
    0066000066330066660066990066CC0066FF
    0099000099330099660099990099CC0099FF
    00CC0000CC3300CC6600CC9900CCCC00CCFF
    00FF0000FF3300FF6600FF9900FFCC00FFFF
    3300003300333300663300993300CC3300FF
    3333003333333333663333993333CC3333FF
    3366003366333366663366993366CC3366FF
    3399003399333399663399993399CC3399FF
    33CC0033CC3333CC6633CC9933CCCC33CCFF
    33FF0033FF3333FF6633FF9933FFCC33FFFF
    6600006600336600666600996600CC6600FF
    6633006633336633666633996633CC6633FF
    6666006666336666666666996666CC6666FF
    6699006699336699666699996699CC6699FF
    66CC0066CC3366CC6666CC9966CCCC66CCFF
    66FF0066FF3366FF6666FF9966FFCC66FFFF
    9900009900339900669900999900CC9900FF
    9933009933339933669933999933CC9933FF
    9966009966339966669966999966CC9966FF
    9999009999339999669999999999CC9999FF
    99CC0099CC3399CC6699CC9999CCCC99CCFF
    99FF0099FF3399FF6699FF9999FFCC99FFFF
    CC0000CC0033CC0066CC0099CC00CCCC00FF
    CC3300CC3333CC3366CC3399CC33CCCC33FF
    CC6600CC6633CC6666CC6699CC66CCCC66FF
    CC9900CC9933CC9966CC9999CC99CCCC99FF
    CCCC00CCCC33CCCC66CCCC99CCCCCCCCCCFF
    CCFF00CCFF33CCFF66CCFF99CCFFCCCCFFFF
    FF0000FF0033FF0066FF0099FF00CCFF00FF
    FF3300FF3333FF3366FF3399FF33CCFF33FF
    FF6600FF6633FF6666FF6699FF66CCFF66FF
    FF9900FF9933FF9966FF9999FF99CCFF99FF
    FFCC00FFCC33FFCC66FFCC99FFCCCCFFCCFF
    FFFF00FFFF33FFFF66FFFF99FFFFCCFFFFFF

    Setting Text Color

    To set the text color in HTML, we specify the color value of text inside the color property of style attribute. The value of color can be specified using any of the above discussed methods.

    Example

    The following example shows how to set color for a text using color name method:

    <!DOCTYPE html><html><head><title>Setting HTML Text Color </title></head><body><h2 style="color: Fuchsia;">Setting Text Color in HTML</h3><p style="color: Teal;">This line is created using paragraph tag and its color is <b>Teal</b>. </p><p style="color: SlateBlue;">This is another line created using paragraph tag and its color is <b>SlateBlue</b>. </p></body></html>

    The above HTML code will generate one heading and two different paragraphs with distinct colors.

    Setting Background Color

    To set the background color for any HTML element, we specify the color value inside the background-color property of the style attribute. The value of color can be specified using any of the above-discussed methods.

    Example

    The following example shows how to set background color for HTML elements using color name method:

    <!DOCTYPE html><html><head><title>Background Color </title></head><body><h2 style="background-color: Fuchsia;">Setting Background Color in HTML</h3><p style="background-color: Teal;">This line is created using paragraph tag and its background color is <b>Teal</b>.</p><p style="background-color: SlateBlue;">This is another line created using paragraph tag and its background color is <b>SlateBlue</b>.</p></body></html>

    On executing the above HTML code, it will generate one heading and two different paragraphs with distinct background colors.

    Setting Border Color

    To set the border color for any HTML element, we specify the color value inside the border property of the style attribute. The value of color can be specified using any of the above-discussed methods.

    Example

    In the following example, we are going to set border color for HTML elements using color name method:

    <!DOCTYPE html><html><head><title>Border Color </title></head><body><h2 style="border: 2.5px solid Fuchsia;">Setting Border Color in HTML</h3><p style="border: 2.5px dotted Teal;">This line is created using paragraph tag and its border color is <b>Teal</b>. </p><p style="border: 2.5px dashed SlateBlue;">This is another line created using paragraph tag and its border color is <b>SlateBlue</b>. </p></body></html>

    When we execute the above HTML code, it will generate one heading and two different paragraphs with distinct border colors.

  • Comments

    HTML comments are non-executable lines of code that do not display on the webpage and are used to add notes or explanations. It is a good practice to add comments into your HTML code, especially in complex documents, to indicate sections of a document and any other notes to anyone looking at the code.

    HTML comments are completely ignored by web browsers, so they don’t affect how your page looks or works.

    HTML comments help you and others understand your code and increase code readability and are placed in between <!– … –> tags. So, any content placed with <!–… –> tags will be treated as a comment and will be completely ignored by the browser.

    Example of HTML Comments

    Here’s an example of HTML comments:

    Open Compiler

    <!DOCTYPE html><html><head><!-- Document Header Starts --><title>This is document title</title></head><!-- Document Header Ends --><body><p>Document content goes here.....</p></body></html>

    If you run the above program, it displays the sentence “Document content goes here…..” neglecting the content given as a part of comments.

    Valid vs Invalid Comments

    Comments in HTML have certain rules that you need to follow. Below is the list of rules −

    • Comments do not support nesting, which means a comment cannot be put inside another comment.
    • You can’t have the sequence “–” within a comment, except to close it.
    • You must also make sure that there are no spaces in the start-of-comment string.

    Example

    Here, the given comment is a valid comment and will be wiped off by the browser.

    Open Compiler

    <!DOCTYPE html><html><head><title>Valid Comment Example</title></head><body><!--   This is valid comment --><p>Document content goes here.....</p></body></html>

    But the following line is not a valid comment and will be displayed by the browser. This is because there is a space between the left angle bracket and the exclamation mark.

    Open Compiler

    <!DOCTYPE html><html><head><title>Invalid Comment Example</title></head><body>
       < !--   This is not a valid comment -->
       <p>Document content goes here.....</p></body></html>

    Multiline Comments

    You can comment multiple lines by the special beginning tag <!– and ending tag –> placed before the first line and end of the last line as shown in the given example below.

    Example

    Open Compiler

    <!DOCTYPE html><html><head><title>Multiline Comments</title></head><body><!--
    
      This is a multiline comment and it can
      span through as many as lines you like.
    --><p>Document content goes here.....</p></body></html>

    Conditional Comments

    Conditional comments are a feature specific to Internet Explorer (IE) on Windows, but they are ignored by other browsers. They are supported from Explorer 5 onwards, and you can use them to give conditional instructions to different versions of IE.

    Example

    Open Compiler

    <!DOCTYPE html><html><head><title>Conditional Comments</title><!--[if IE 6]>
    
      Special instructions for IE 6 here
    <![endif]--></head><body><p>Document content goes here.....</p></body></html>

    These tags are used in the situation where you need to apply different style sheets based on different versions of Internet Explorer; in such a situation, conditional comments will be helpful.

    Comments Using <comment> Tag

    There are few browsers that support the <comment> tag to comment on a part of HTML code.

    Example

    Open Compiler

    <!DOCTYPE html><html><head><title>Using Comment Tag</title></head><body><p>This is <comment>not</comment> Internet Explorer.</p></body></html>

    Commenting Script Code

    If an HTML document contains JavaScript or VbScript and you’re opening this page on the browser, some old versions of Browser may not work properly. It is recommended to put that script code inside proper HTML comments so that old browsers can work properly.

    Example

    <!DOCTYPE html><html><head><title>Commenting Script Code</title><script><!-- document.write("Hello World!") --></script></head><body><p>Hello , World!</p></body></html>

    Commenting Style Sheets

    To comment a CSS script within a <style> tag, we need to use the /* symbol as a starting point and the */ symbol as an ending.

    Example

    <!DOCTYPE html><html><head><title>Commenting Style Sheets</title><style>
    
      /* commenting in stylesheet 
         .example {
         border: 1px solid #4a7d49;
      } */
    </style></head><body><div class="example">Hello , World!</div></body></html>
  • Quotations

    HTML quotations allow you to include and format quoted text within your web content. HTML provides tags such as <blockquote><q><cite><address><bdo>, and <abbr> to structure and style quotes.

    These quotation tags help maintain proper formatting and semantics, enhancing the presentation and meaning of quoted content on web pages. Incorporating quotes is essential for conveying information accurately and providing a well-organized reading experience for users.

    HTML Quotation Elements

    The following are the quotation elements that are used to insert and display quotations on the webpage:

    TagDescription
    <q>Defines a short inline quotation.
    <blockquote>Defines a block-level indented quotation.
    <cite>Specifies a reference to the title of a creative work, such as books or articles.
    <address>Defines contact information.
    <bdo>Overrides text direction.
    <abbr>Defines an abbreviation or acronym.

    Short Quotation (<q>)

    The <q> tag is used to define short (or inline) quotation marks in HTML, and the browsers often add quotation marks around it.

    Syntax

    The syntax to define a short quotation is:

    <q>The content to be quoted</q>

    Example

    Following is an example of displaying a short (or inline) quotation on the webpage:

    <!DOCTYPE html><html><head><title>HTML Quotation tag</title></head><body><p>DLF stands for <q>Delhi Land and Finance</q></p><p>Delhi Land and Finance is one of the largest commercial real estate developer in India.</p></body></html>

    Example

    In the example below, we used the <q> tag on a particular text inside the <h1> tag:

    <!DOCTYPE html><html><head><title>HTML u tag</title></head><body><h1>Welcome to <q> INDIA </q> Kids.</h1></body></html>

    Block-level Quotation (<blockquote>)

    The <blockquote> tag is to indicate long quotations. It should contain only block-level elements within it and not just plain text. It specifies a section quoted from another source and contains only block-level elements.

    We can also use the cite attribute inside the <blockquote> tag to indicate the source of the quotation in URL form.

    Syntax

    The syntax to define a block-level quotation is:

    <blockquote>The multiple line content to be quoted </blockquote>

    Example

    Following is an example of displaying a block-level quotation on the webpage:

    <!DOCTYPE html><html><head><title>HTML blockquote tag</title></head><body><p>DLF stands for Delhi Land and Finance</p><blockquote>Delhi Land and Finance is one of the largest commercial real estate developers in India. It is also engaged in the business of generation of power provision of maintenance services hospitality and recreational activities life insurance and retail chain outlets. Its internal business includes the development business and rental business. The development business of the Company is involved in the sale of residential spaces select commercial offices and commercial complexes. The company has a unique business model with earnings arising from development and rentals. </blockquote></body></html>

    Example

    Folloiwng is an example of using the “cite” attribute with the <blockquote> tag:

    <!DOCTYPE html><html><head><title>HTML blockquote tag</title></head><body><h1>Tutorialspoint</h1><p>Here is a quotation from Tutorialspoints official website</p><blockquote cite="https://www.tutorialspoint.com">Join our millions of loyal visitors to access our free Text Library. From programming languages and web development to data science and cybersecurity, our masterfully crafted Tutorials will help you master any technology or concept from scratch.</blockquote></body></html>

    Styling Quotation (<blockquote>)

    You can style the <blockquote> tag using the CSS to give it a better look as per your webpage theme.

    In the following example, we are setting some CSS properties such as background color, border, border width, and font color to make it more attractive:

    <!DOCTYPE html><html><head><title>HTML blockquote tag</title><style>
    
      blockquote {
         background-color: #006969;
         color: #fff;
         border: 1px solid #333;
         border-radius: 8px;
         font-weight: 500;
         padding: 8px;
      }
    </style></head><body><h1>Tutorialspoint</h1><p>Here is a quotation from Tutorialspoints official website</p><blockquote cite="https://www.tutorialspoint.com">Join our millions of loyal visitors to access our free Text Library. From programming languages and web development to data science and cybersecurity, our masterfully crafted Tutorials will help you master any technology or concept from scratch.</blockquote></body></html>

    Cite a Quote (<cite>)

    The <cite> tag is used to reference the title of a creative work, such as a book, movie, or song, within the content. It provides semantic meaning to the citation.

    Example

    Here’s a coding example −

    <!DOCTYPE html><html><head><title>Cite Tag Example</title></head><body><p>The information is sourced from <cite>The Elements of Style</cite> by Strunk and White.</p></body></html>

    In this example, ‘<cite>’ is used to indicate the title of the referenced book.

    Contact Information (<address>)

    The <address> tag is used to define the contact information for the author or owner of a document. It often includes details such as an email address, physical address, or other relevant contact information.

    Example

    Here’s an example −

    <!DOCTYPE html><html><head><title>Address Tag Example</title></head><body><address>
       Contact us at: <a href="mailto:[email protected]">[email protected]</a><br>
       Visit us at: 123 Main Street, Cityville
    </address></body></html>

    In this example, the ‘<address>’ tag is used to provide contact information, including an email link and a physical address.

    Bi-Directional Override (<bdo>)

    The <bdo> tag in HTML, bdo stands for Bi-Directional Override, is used to override the current text direction. It is commonly used in situations where the default text direction needs to be changed, such as for displaying text from right to left.

    Example

    Here’s an example −

    <!DOCTYPE html><html><head><title>Bi-Directional Override Example</title></head><body><p>This text will go left to right.</p><p><bdo dir="rtl">This text will go right to left.</bdo></p></body></html>

    In this example, the text within the ‘<bdo>’ tag is displayed from right to left, overriding the default left-to-right direction.

    Abbreviations (<abbr>)

    The <abbr> tag is used to define abbreviations or acronyms, i.e., you can define an optional title for full form to a specific word or sentence.

    Example

    Here’s an example −

    <!DOCTYPE html><html><head><title>Abbreviation Tag Example</title></head><body><p>Tim Berners-Lee, a British scientist, invented the <abbr title="World Wide Web">WWW</abbr> in 1989.</p></body></html>

    In this example, <abbr> is used to abbreviate “World Wide Web” to “WWW,” and the ‘title‘ attribute provides the full description of the abbreviation.

  • Formatting

    HTML formatting defines the way of content representation on the webpage to improve the readability, to give the semantic meaning, and to improve visual styling.

    HTML formatting is done by using HTML physical and logical tags. In this chapter, we will learn about the text appearance with HTML formatting.

    Let’s understand what are physical and logical tags:

    • Physical Tags: These tags are used to give the visual appearance to the textual content.
    • Logical Tags: These tags are used to give logical and semantic meaning to the textual content. There are a few logical tags that are used for screen readers, but the impact of those tags is visible on the browsers.
    HTML Text Formatting

    Use of HTML Formatting

    Without formatting, nothing looks good or soothing to our eyes. But HTML formatting is not only for soothing the eye or making textual content attractive. There are few reasons to do the HTML formatting.

    HTML formatting is useful in many aspects:

    • The appearance of any text provides a clear view of the content intent, such as highlighting the keywords, putting meaningful information in the quotations, underlining the main sentence, etc.
    • Formatting helps search engines understand the content structure and is also helpful for search engine optimization.
    • Formatting improves the visual layout and improves the readability of the content.

    HTML Formatting Tags

    The following table has a list of common HTML formatting tags that are used for text formatting:

    TagDescriptionCategory
    <b>This tag is used to make the text bold.Physical Tag
    <i>This tag is used to make the text italic.Physical Tag
    <big>This tag is used to make the text bigger. It is not supported in HTML5.Physical Tag
    <small>This tag is used to make the text smaller.Physical Tag
    <u>This tag is used to underline text.Physical Tag
    <strike>This tag is used to strike through text. It is not supported in HTML5.Physical Tag
    <tt>This tag is used to make text appear in teletype (monospace font). It is not supported in HTML5.Physical Tag
    <strong>This tag is used to bold text and give it semantic importance.Logical Tag
    <em>This tag is used to italicize text and give it semantic emphasis.Logical Tag
    <sup>This tag is used to make superscript text (slightly above the normal line).Other Tag
    <sub>This tag is used to make subscript text (slightly below the normal line).Other Tag
    <ins>This tag is used to indicate that content has been added (typically underlined).Other Tag
    <del>This tag is used to indicate that content has been deleted (typically struck through).Other Tag
    <mark>This tag is used to highlight text with a yellow background.Other Tag

    HTML Formatting Tags with Examples

    The detailed explanation of each formatting tag with their examples is as follows:

    HTML <b> Tag

    HTML <b> tag is used for making the text bold; there is no logical aspect of this tag; it is only used for visual impact.

    Example

    This example demonstrates the use of the <b> tag to make the text formatting bold:

    <!DOCTYPE html><html><head><title>Bold Text Example</title></head><body><p>The following word uses a <b>bold</b> typeface.</p></body></html>

    Output:

    The following word uses a bold typeface.

    HTML <strong> Tag

    HTML <strong> tag is used for making the text strong that has more importance, and the text inside it is typically displayed in the bold.

    Note: The <b> tag makes the text bold for styling purposes only, while the <strong> tag makes the text bold and also adds importance to the text within its content.

    Example

    This example demonstrates the use of the <strong> tag to show the important text:

    <!DOCTYPE html><html><head><title>Bold Text Example</title></head><body><p>The following word uses a <strong>strong</strong> typeface.</p></body></html>

    Output

    The following word uses a strong typeface.

    HTML <i> Tag

    Any content that is enclosed within the <i>…</i> element is displayed in italicized.

    Example

    This example demonstrates the use of the <i> tag to make the text italic:

    <!DOCTYPE html><html><head><title>Italic Text Example</title></head><body><p>The following word uses a <i>italicized</i> typeface.</p></body></html>

    Output:

    The following word uses a italicized typeface.

    HTML <em> Tag

    HTML <em> tag gives semantic meaning to the text contained within it and renders it in italics on the browser.

    Example

    This example demonstrates the use of the <em> tag to make the text emphasize:

    <!DOCTYPE html><html><head><title>Italic Text Example</title></head><body><p>The following word uses a <em>emphasized</em> typeface.</p></body></html>

    Output:

    The following word uses a emphasized typeface.

    HTML <big> Tag

    Any content that is enclosed within the <big>…</big> element is displayed one font size larger than the rest of the text surrounding it.

    Example

    This example demonstrates the use of the <big> tag to make the text appear larger than the surrounding text:

    <!DOCTYPE html><html><head><title>Larger Text Example</title></head><body><p>Hello Welcome to <big>Tutorialspoint</big>.</p></body></html>

    Output:

    Hello Welcome to Tutorialspoint.

    HTML <small> Tag

    The content, which is enclosed within the <small>…</small> element, is displayed one font size smaller than the rest of the text surrounding it.

    Example

    This example demonstrates the use of the <small> tag to make the text appear smaller than the surrounding text:

    <!DOCTYPE html><html><head><title>Smaller Text Example</title></head><body><p>Hello Welcome to <small>Tutorialspoint</small>.</p></body></html>

    Output:

    Hello Welcome to Tutorialspoint.

    HTML <sup> Tag

    Any content enclosed within the <sup>…</sup> element is written in superscript; the font size used is the same size as the characters surrounding it but is displayed at half the height of the surrounding characters, giving it a smaller and slightly raised appearance compared to the rest of the text.

    Example

    This example demonstrates the use of the <sup> tag to make the text appear slightly above the normal text:

    <!DOCTYPE html><html><head><title>Superscript Text Example</title></head><body><p>The following word uses a <sup>superscript</sup> typeface. </p></body></html>

    Output:

    The following word uses a superscript typeface. 

    HTML <sub> Tag

    Any content of a <sub>…</sub> element is written in subscript; the font size used is the same as the characters surrounding it and is displayed half a character’s height beneath the other characters. It is typically used for writing things like chemical formulas, where certain characters need to be displayed below the regular text line.

    Example

    This example demonstrates the use of the <sub> tag to make the text appear slightly below the normal text:

    <!DOCTYPE html><html><head><title>Subscript Text Example</title></head><body><p>The following word uses a <sub>subscript</sub> typeface. </p></body></html>

    Output:

    The following word uses a subscript typeface. 

    HTML <ins> Tag

    Any content that is enclosed within the <ins>…</ins> element is displayed as inserted text.

    Example

    This example demonstrates the use of the <ins> tag to mark the text that has been inserted:

    <!DOCTYPE html><html><head><title>Inserted Text Example</title></head><body><p>I want to drink <del>cola</del><ins>wine</ins></p></body></html>

    Output:

    I want to drink cola wine

    HTML <del> Tag

    Content that is enclosed within the <del>…</del> element is displayed as deleted text.

    Example

    This example demonstrates the use of the <del> tag to mark the text that has been removed:

    <!DOCTYPE html><html><head><title>Deleted Text Example</title></head><body><p>Hello welcome to <del>Madras</del><ins>Chennai</ins></p></body></html>

    Output:

    Hello welcome to Madras Chennai

    HTML <u> Tag

    Any content enclosed within the <u>…</u> element is displayed with an underline.

    Example

    This example demonstrates the use of the <u> tag to make the underlined text:

    <!DOCTYPE html><html><head><title>Underlined Text Example</title></head><body><p>The following word uses a <u>underlined</u> typeface.</p></body></html>

    Output:

    The following word uses a underlined typeface.

    HTML <strike> Tag

    Content that is enclosed within the <strike>…</strike> element is displayed with strikethrough, which is a thin line through the text.

    Example

    This example demonstrates the use of the <strike> tag to display strikethrough text:

    <!DOCTYPE html><html><head><title>Strike Text Example</title></head><body><p>The following word uses a <strike>strikethrough</strike> typeface.</p></body></html>

    Output:

    The following word uses a strikethrough typeface.

    HTML <mark> Tag

    HTML <mark> tag is used to mark or highlight text that is important for notation purposes.

    Example

    This example demonstrates the use of the <mark> tag to make the marked text:

    <!DOCTYPE html><html><head><title>Strike Text Example</title></head><body><p>The following word uses a <mark>strikethrough</mark> typeface.</p></body></html>

    Output:

    The following word uses a marked typeface.

    HTML <tt> Tag

    Any content enclosed within the <tt>…</tt> element is written in monospaced font. Most of the fonts are known as variable-width fonts because different letters are of different widths (for example, the letter ‘m’ is wider than the letter ‘i’). In a monospaced font, however, each letter has the same width.

    Example

    This example demonstrates the use of the <tt> tag to make the teletype text:

    <!DOCTYPE html><html><head><title>Monospaced Font Example</title></head><body><p>The following word uses a <tt>monospaced</tt> typeface.</p></body></html>

    Output:

    The following word uses a monospaced typeface.

  • Style Sheet

    CSS, or Cascading Style Sheets, is a tool that defines how web documents look on screens or in print. Since its introduction in 1994, the W3C has encouraged the use of style sheets for web design. CSS lets you control the presentation of your content, whether it’s on a screen, in print, or for accessibility, making web design more flexible and efficient.

    Cascading Style Sheets (CSS) provide easy and effective alternatives to specify various attributes for the HTML tags. Using CSS, you can specify a number of style properties for a given HTML element.

    Each property has a name and a value, separated by a colon (:). Each property declaration is separated by a semicolon (;).

    Example of CSS on HTML Document

    First, let’s consider an example of an HTML document that makes use of <font> tag and associated attributes to specify text color and font size:

    <!DOCTYPE html><html><head><title>HTML CSS</title></head><body><p><font color="green" size="5">Hello, World!</font></p></body></html>

    We can rewrite the above example with the help of CSS as follows:

    <!DOCTYPE html><html><head><title>HTML CSS</title></head><body><p style="color:green;font-size:24px;">
    
      Hello, World!
    </p></body></html>

    Cascading means that a style applied to a parent element will also apply to all children elements within the parent. So when you are applying any style to an element, you have to be careful about child elements. You can apply different styles to children also.

    Ways to Use CSS (Style Sheets) in HTML

    There are three ways to include CSS in your HTML document:

    • External CSS: Define style sheet rules in a separate .css file and then include that file in your HTML document using HTML <link> tag.
    • Internal CSS: Define style sheet rules in the header section of the HTML document using <style> tag.
    • Inline CSS: Define style sheet rules directly along-with the HTML elements using style attribute.

    Examples of Using Style Sheet in HTML

    Let’s see all three ways one by one with the help of suitable examples.

    Using External CSS

    If you need to use your style sheet (CSS) on various pages, then it’s always recommended to define a common style sheet in a separate file. A CSS file will have an extension as “.css”, and it will be included in HTML files using the <link> tag.

    Consider we define a style sheet file style.css, which has the following rules:

    style.css

    .red{
       color: red;
    }
    .thick{
       font-size:20px;
    }
    .green{
       color:green;
    }
    

    Here we defined three CSS rules that will be applicable to three different classes defined for the HTML tags. I suggest you should not bother about how these rules are being defined because you will learn them while studying CSS.

    Example to Use External CSS file in HTML

    Now let’s make use of the above external CSS file in our following HTML document.

    <!DOCTYPE html><html><head><title>HTML External CSS</title><link rel="stylesheet" type="text/css" href="/html/style.css"></head><body><p class="red">This is red</p><p class="thick">This is thick</p><p class="green">This is green</p><p class="thick green">
    
      This is thick and green
    </p></body></html>

    Using Internal CSS

    If you want to apply Style Sheet rules to a single document only, then you can include those rules in the header section of the HTML document using <style> tag. Rules defined in the internal style sheet override the rules defined in an external CSS file.

    Example to Use Internal CSS in HTML

    Let’s rewrite the above example once again, but here we will write style sheet rules in the same HTML document using <style> tag.

    <!DOCTYPE html><html><head><title>HTML Internal CSS</title><style type="text/css">
    
      .red {
         color: red;
      }
      .thick {
         font-size: 20px;
      }
      .green {
         color: green;
      }
    </style></head><body><p class="red">This is red</p><p class="thick">This is thick</p><p class="green">This is green</p><p class="thick green">
      This is thick and green
    </p></body></html>

    Using Inline CSS

    You can apply style sheet rules directly to any HTML element using the style attribute of the relevant tag. This should be done only when you are interested in making a particular change in any HTML element. Rules defined inline with the element override the rules defined in an external CSS file as well as the rules defined in <style> element.

    Example to Use Inline CSS in HTML

    Let’s rewrite the above example once again, but here we will write style sheet rules along with the HTML elements using style attribute of those elements.

    <!DOCTYPE html><html><head><title>HTML Inline CSS</title></head><body><p style="color:red;">This is red</p><p style="font-size:20px;">This is thick</p><p style="color:green;">This is green</p><p style="color:green;font-size:20px;">
    
      This is thick and green
    </p></body></html>
  • Block and Inline Elements

    HTML block elements are used to create the logical and semantic layout of a web page. They help to organize the content into meaningful sections and make it easier for browsers, search engines, and site visitors to understand the structure and meaning of different parts of the web page. Inline elements are used to make useful block elements, like adding anchor links.

    There are various tags that you can use to create blocks, such as <div><p><table>, and so on.

    All the HTML elements can be categorized into two categories:

    • Block-level Elements
    • Inline Elements

    HTML Block-level Elements

    Block-level elements start on a new line, and anything that follows them appears on the next line. These elements may contain margins to add some space before and after. These elements take up the full width of their parent elements by default; you may set their width by using the CSS width property.

    List of HTML Block-level Elements

    The following table has the list of all block-level elements −

    HTML Block Elements
    <address><article><aside><blockquote><canvas>
    <dd><div><dl><dt><fieldset>
    <figcaption><figure><footer><form><h1> – <h6>
    <header><hr><li><main><nav>
    <noscript><ol><p><pre><section>
    <table><tfoot><ul><video>

    Example of Block-level Elements

    The following example demonstrates the block-level elements. Here, we are using one heading and two paragraphs separated by a horizontal line.

    <!DOCTYPE html><html><head><title>HTML Block Level Elements</title></head><body><h3>HTML Block Level Elements</h3><p>
    
      This line will appear in the next line
      after Heading.
    </p><hr /><p>
      This line will appear after Horizontal
      Line.
    </p></body></html>

    HTML Inline Elements

    Inline elements can appear within the same line and do not start a new line on their own.

    List of HTML Inline Elements

    The following table lists down all the inline elements −

    HTML Inline Elements
    <a><abbr><acronym><b><bdo>
    <big><br><button><cite><code>
    <dfn><em><i><img><input>
    <kbd><label><map><object><output>
    <q><samp><script><select><small>
    <span><strong><sub ><sup><textarea>
    <time><tt><var>

    Example of Inline Elements

    The following example demonstrates inline elements. Here, we are making the paragraph’s text bold and italic using inline emelents <b> and <i> −

    <!DOCTYPE html><html><head><title>HTML inline Element</title></head><body><h3>Inline Elements in HTML</h3><!-- Using <b> inline element --><p>This <b>paragraph</b> is bold. </p><!-- Using <i> inline element  --><p>This is an <i>italic</i> paragraph.</p></body></html>

    Grouping Block and Inline Elements

    Block-level and inline elements can be grouped using the <div> tag. The <div> tag is a block-level element that plays a big role in grouping various other HTML tags and applying CSS to groups of elements.

    Example

    This example demonstrates the group of elements using the div tag −

    <!DOCTYPE html><html><head><title>HTML div Tag</title></head><body><!-- First group of tags --><div style="background-color:yellow"><h4>This is first group</h4><p>Following is a list of vegetables</p><ul><li>Beetroot</li><li>Ginger</li><li>Potato</li><li>Radish</li></ul></div><!-- Second group of tags --><div style="background-color:cyan"><h4>This is second group</h4><p>Following is a list of fruits</p><ul><li>Apple</li><li>Banana</li><li>Mango</li><li>Strawberry</li></ul></div></body></html>

  • Fonts

    HTML fonts play an important role in making a website more user-friendly and increasing content readability. Font face and color depend entirely on the computer and browser that are being used to view your page, but you can use the HTML <font> tag to add style, size, and color to the text on your website. You can also use a <basefont> tag to set all of your text to the same size, face, and color.

    HTML <font> Tag

    The HTML <font> tag specifies the size, color, and face (family) of the text to be displayed on the webpage.

    The <font> tag has three attributes called size, color, and face to customize your fonts. To change any of the font attributes at any time within your webpage, simply use the <font> tag with the attribute names and values. The text that follows will remain changed until you close with the </font> tag. You can change one or all of the font attributes within one <font> tag.

    The font and basefont tags are deprecated, and they are supposed to be removed in a future version of HTML. So they should not be used; rather, it’s suggested to use CSS styles to manipulate your fonts. But still, for learning purposes, this chapter will explain font and basefont tags in detail.

    Set Font Size

    To set the font size of a web page, we use the size attribute. This attribute allows us to set the font size between 1 and 7, where 1 is the smallest font size whereas 7 is the largest. The default size of a font is 3.

    Example

    The following example shows how to use the “size” attribute of the <font> tag to set the font size:

    <!DOCTYPE html><html><head><title>Setting Font Size</title></head><body><font size = "1">Font size = "1"</font><br /><font size = "2">Font size = "2"</font><br /><font size = "3">Font size = "3"</font><br /><font size = "4">Font size = "4"</font><br /><font size = "5">Font size = "5"</font><br /><font size = "6">Font size = "6"</font><br /><font size = "7">Font size = "7"</font></body></html>

    Relative Font Size

    In HTML, relative font size means specifying how many sizes larger or smaller than the preset font size should be. We can specify it like <font size = “&plus;n”> or <font size = “−n”>

    Example

    The code below demonstrates how to set the relative font size of texts in a web page:

    <!DOCTYPE html><html><head><title>Relative Font Size</title></head><body><font size = "-1">Font size = "-1"</font><br /><font size = "+1">Font size = "+1"</font><br /><font size = "+2">Font size = "+2"</font><br /><font size = "+3">Font size = "+3"</font><br /><font size = "+4">Font size = "+4"</font></body></html>

    Setting Font Face

    You can set the font face (family) using the face attribute, but be aware that if the user viewing the page doesn’t have the font installed, they will not be able to see it. Instead, the user will see the default font face applicable to the user’s computer.

    Example

    In this example, we are setting multiple font faces to the text by using the “face” attribute:

    <!DOCTYPE html><html><head><title>Font Face</title></head><body><font face = "Times New Roman" size = "5">Times New Roman</font><br /><font face = "Verdana" size = "5">Verdana</font><br /><font face = "Comic sans MS" size =" 5">Comic Sans MS</font><br /><font face = "WildWest" size = "5">WildWest</font><br /><font face = "Bedrock" size = "5">Bedrock</font><br /></body></html>

    Specify Alternate Font Faces

    A visitor will only be able to see your font if they have that font installed on their computer. So, we can specify two or more font face alternatives by listing the font face names, separated by a comma.

    <font face = "arial, helvetica"><font face = "Lucida Calligraphy, Comic Sans MS, Lucida Console">

    When your page is loaded, their browser will display the first font face available. If none of the given fonts are installed, then it will display the default font, Times New Roman.

    Setting Font Color

    We can set any font color of our choice to the texts using the color attribute. To specify the color, we can use either the color name or hexadecimal code of that color.

    Note − You can check a complete list of HTML Color Name with Codes.

    Example

    The following example illustrates how to set color to the texts on a web page:

    <!DOCTYPE html><html><head><title>Setting Font Color</title></head><body><font color = "#FF00FF">This text is in pink</font><br /><font color = "red">This text is red</font></body></html>

    The <basefont> Element

    The <basefont> element is used to set a default font size, color, and typeface for any parts of the document that are not otherwise contained within a <font> tag. You can use the <font> elements to override the <basefont> settings.

    Like the <font> tag, the <basefont> tag also takes color, size, and face attributes, and it will support relative font setting by giving size a value of +1 for a size larger or −2 for two sizes smaller.

    Example

    In the below HTML code, we are illustrating the use of the “basefont” tag:

    <!DOCTYPE html><html><head><title>Setting Basefont Color</title></head><body><basefont face = "arial, verdana, sans-serif" size = "2" color = "#ff0000"><p>This is the page's default font.</p><h2>Example of the &lt;basefont&gt; Element</h2><p><font size = "+2" color = "darkgray">
    
            This is darkgray text with two sizes larger
         &lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font face = "courier" size = "-1" color = "#000000"&gt;
            It is a courier font, a size smaller and black in color.
         &lt;/font&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    The above HTML code will produce four line of text with different font face, color and sizes.

    Using Web Safe Fonts in HTML

    CSS3 has adapted font combinations technology. If the browser doesn't support the first font, then it tries the next font. Here is the list of CSS Web Safe Fonts.

    HTML Fonts Reference

    Read more about HTML fonts, visit:HTML Fonts Reference

  •  Paragraphs

    HTML Paragraphs

    HTML paragraphs are block-level elements that are used to structure and format text content on a webpage. A paragraph is basically a collection of words and punctuation together. It allows us to organize and present textual information in a coherent and readable manner. The HTML <p> tag is used to create a paragraph element.

    Example

    This is the first paragraph: Hello World!.

    This is the second paragraph: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc ut purus maximus, efficitur nibh non, gravida odio. Suspendisse justo tortor, consequat sed mauris sit amet, varius fringilla arcu. Duis et elit quis metus molestie lacinia.

    Reason to Use Paragraphs

    Paragraphs typically create space above and below the text, separating it from surrounding content. They can be styled using CSS to control aspects such as font size, color, alignment, and spacing. In web development, paragraphs play a crucial role in conveying information effectively, enabling clear communication, and enhancing the overall user experience on a website.

    Creating a Paragraph

    To create a paragraph in HTML, use the <p> tag. Place text inside <p> and </p> that you want to display as a paragraph on a webpage.

    Syntax

    Below is the syntax to create a paragraph in HTML:

    <p>Text to display as a paragraph on the webpage</p>

    Example of HTML Paragraph

    In the following example, we are creating two paragraphs:

    To create two paragraphs:

    <!DOCTYPE html><html><head></head><body><p>Lorem ipsum odor amet, consectetuer adipiscing elit. Proin eros habitant accumsan vulputate curae eu fusce vehicula.</p><p>Laoreet sociosqu taciti iaculis cras leo nec litora. Nisi vehicula massa fusce justo libero duis. Per condimentum vivamus nec elementum nullam sociosqu vel scelerisque.</p></body></html>

    Line Breaks With Paragraphs

    The <br> tags are used to insert line breaks within a paragraph to control the text layout.

    Example

    The following example demonstrates how you can use line breaks with the HTML paragraph:

    <!DOCTYPE html><html><head><title>Line Breaks With Paragraphs</title></head><body><p>This is a paragraph with a <br> line break. </p></body></html>

    Headings With Paragraphs

    Headings, such as <h1>, provide a hierarchical structure and can be used alongside paragraphs.

    Example

    This example shows a heading with the paragraph:

    <!DOCTYPE html><html><head><title>Headings With Paragraphs</title></head><body><h1>Main Heading</h1><p> This is a paragraph beneath the main heading. </p></body></html>

    Lists With Paragraphs

    Lists can be incorporated within paragraphs for content organization.

    Example

    This example shows a paragraph with an unordered list:

    <!DOCTYPE html><html><head><title>Lists With Paragraphs</title></head><body><p>This is a paragraph following an unordered list.</p><ul><li>Item 1</li><li>Item 2</li></ul></body></html>

    Emphasis Within Paragraphs

    Tags like <em> and <strong> allow you to emphasize text within paragraphs.

    Example

    This example demonstrates the use of em and strong tags inside a paragraph, like how you can use formatting tags with an HTML paragraph:

    <!DOCTYPE html><html><head><title>Emphasis Within Paragraphs</title></head><body><p> This is a <em> paragraph </em> with <strong> emphasized </strong> text. </p></body></html>

    Links within Paragraphs

    You can insert links within paragraphs using the <a> tag.

    Example

    This example demonstrates how you can place the links inside a paragraph:

    <html><head><title>Links within Paragraphs</title></head><body><p>Visit our website <a href="https://www.tutorialspoint.com">here </a>. </p></body></html>

    Inline Styles Within Paragraphs

    You can use the <span> tag with inline styles to apply specific formatting.

    Example

    This example demonstrates how you can apply inline CSS styles to some of the parts of the text inside a paragraph:

    <html><head><title>Inline Styles Within Paragraphs</title></head><body><p>This is a <span style="color: blue;">blue</span> text within a paragraph. </p></body></html>

    Images Within Paragraphs

    You can embed images within paragraphs using the <img> tag.

    Example

    In this example, we are displaying an image inside a paragraph:

    <html><head><title>Images Within Paragraphs</title></head><body><p> Here's an image: <img src="\html\images\test.png" alt="Example Image"></p></body></html>

    Superscript and Subscript Within Paragraphs

    Use <sup> and <sub> tags to create superscript and subscript text.

    Example

    This example demonstrates how you can display superscripted and subscripted text inside a paragraph:

    <html><head><title>Superscript and Subscript Within Paragraphs</title></head><body><p> H<sub>2</sub>O is the chemical formula for water. 2<sup>3</sup> equals 8.</p></body></html>

    Abbreviations Within Paragraphs

    The <abbr> tag helps define abbreviations or acronyms.

    Example

    This example shows an abbreviation within a paragraph; it is useful when you want to display an abbreviation or acronym of a specific word:

    <html><head><title>Abbreviations within Paragraphs</title></head><body><p><abbr title="Hypertext Markup Language">HTML</abbr> is used for web development.</p></body></html>

    Citations Within Paragraphs

    The <cite> tag specifies citations and references within paragraphs.

    Example

    This example demonstrates the use of the <cite> tag inside a paragraph:

    <html><head><title>Citations Within Paragraphs</title></head><body><p> The book <cite>War and Peace </cite> is a classic novel. </p></body></html>

    Styling Paragraph with CSS

    The following are the different ways to style HTML paragraphs:

    1. Applying CSS Directly to Paragraphs

    You can apply CSS styles directly to the paragraphs by writting inline CSS using the ‘style’ attribute with the <p> tag.

    <!DOCTYPE html><html><head></head><body><p style="font-size: 24px; color: #f40;">This is the first paragraph.</p><p>This is the second paragraph.</p><p style="font-size: 24px; background-color: #f40; color: #fff;">This is the third paragraph.</p></body></html>

    2. Applying CSS on ‘p’ Element

    You can apply CSS styles to all paragraphs within the HTML document by writing CSS rules for the <p> tag.

    <!DOCTYPE html><html><head><style>
    
      p {
        font-size: 22px;
        color: #f40;
      }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;This is the first paragraph.&lt;/p&gt;&lt;p&gt;This is the second paragraph.&lt;/p&gt;&lt;p&gt;This is the third paragraph.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    3. Using CSS Class with Different Paragraphs

    You can apply CSS styles to specific paragraphs by creating a CSS class and using it with the different paragraphs. For this, use the 'class' attribute with the <p> tag.

    <!DOCTYPE html><html><head><style>
    
      .special {
        font-size: 24px;
        color: #f40;
      }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;p class="special"&gt;This is the first paragraph.&lt;/p&gt;&lt;p&gt;This is the second paragraph.&lt;/p&gt;&lt;p class="special"&gt;This is the third paragraph.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS provides extensive control over paragraph styles, allowing you to create visually appealing and well-formatted text on your web page.

  • Headings

    HTML headings define the hierarchy (levels) and structure of content on a webpage. They create a visual hierarchy, with the highest-level heading, which is h1, indicating the most important content or the main heading, and lower-level headings like h2h3h4, etc. for subtopics.

    Reason to use Headings

    Headings are crucial for structuring content and providing a clear visual indication of the beginning of new sections or topics. Properly structured headings enhance readability and user experience on websites, ensuring that information is organized and easy to navigate.

    • Heading Impact on SEO: The well-organized headings help search engines to understand the content structure and indexing.
    • Highlighting Important Topics: The use of heading tags properly keeps the content readable.

    HTML Heading Tags

    The headings are defined with headings tags (<h1> to <h6>). It is important to use heading tags to show the content structure on a webpage. HTML has a different level of heading tags. The hierarchy determines the importance of content and aids in creating a clear information flow for both users and search engines.

    Example

    The following example shows the different levels of the HTML heading −

    <!DOCTYPE html><html><body><h1>This is Heading 1 (H1 Tag)</h1><h2>This is Heading 2 (H2 Tag)</h2><h3>This is Heading 3 (H3 Tag)</h3><h4>This is Heading 4 (H4 Tag)</h4><h5>This is Heading 5 (H5 Tag)</h5><h6>This is Heading 6 (H6 Tag)</h6></body></html>

    Hierarchical Structure of Heading Tags

    Below is the list according to the hierarchy of the heading tags (most to least significant) −

    • The <h1> Tag − The top-level heading denotes the main topic or title of the entire page.
    • The <h2> Tag − Subheadings under <h1> represent major sections related to the main topic. They provide a more specific context to the content.
    • The <h3> to <h6> Tags − These tags are used for further subsections or nested content within <h2> headings. They offer a deeper level of hierarchy for organizing content within specific sections.

    Examples of HTML Headings

    In these examples, you will see the usage of all the heading tags to create different types of headings and styling them using the CSS −

    Headings Using <h1> to <h6> Tags

    In this example, we will use the heading tags (h1 to h6); each of them has a different size and weight for the content −

    <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Example of HTML Headings</title></head><body><h1>Heading 1: Main Heading of Page</h1><h2>Heading 2: Section</h2><h3>Heading 3: Subsection</h3><h4>Heading 4: Sub-subsection</h4><h5>Heading 5: Lower-level heading</h5><h6>Heading 6: Lowest-level heading</h6></body></html>

    Styling Headings With CSS

    In the following example, we will apply the style such as font familyfont colorfont size, etc. to the headings −

    <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Example of HTML Headings</title><style>
    
      h1, h2, h3, h4, h5, h6{
       font-family: Verdana;
      }
      h1{
       color: Red;
       font-size: 32px;
      }
      h2{
       color: Green;
       font-size: 30px;
      }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;Heading 1: Main Heading of Page&lt;/h1&gt;&lt;h2&gt;Heading 2: Section&lt;/h2&gt;&lt;h3&gt;Heading 3: Subsection&lt;/h3&gt;&lt;h4&gt;Heading 4: Sub-subsection&lt;/h4&gt;&lt;h5&gt;Heading 5: Lower-level heading&lt;/h5&gt;&lt;h6&gt;Heading 6: Lowest-level heading&lt;/h6&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Here, we have applied "Verdana" font style to all heading tags, defined the "Red" color to H1 heading with the font size 32px, and defined the "Green" color to H2 heading with the font size 30px.

    Using HTML Tags Within Heading Tags

    HTML headings (h1 to h6) serve as the main titles and subheadings for content organization. Within these heading tags, you can use various other HTML tags to enhance and structure your content effectively. Here are some examples −

    The <span> Tag

    You can use the <span> tag to apply inline styles or classes to specific portions of the text within a heading. This allows for custom styling of text within the heading.

    <!DOCTYPE html><html><head><title>Using <span> Tag</title></head><body><h2>This is a <span style="color: blue;">blue</span> word.</h2></body></html>

    The <a>Tag for Links

    To create a link within a heading, use the <a> tag. This is useful for headings that lead to other pages or sections of your website.

    <!DOCTYPE html><html><head><title>Using <a> Tag for Links</title></head><body><h1><a href="https://www.tutorialspoint.com">Visit our website</a></h1></body></html>

    The <em> and <strong> Tags

    These tags are used for emphasizing text within headings. The <em> tag italicizes the text, while <strong> makes it bold.

    <!DOCTYPE html><html><head><title>Using <em> and <strong> Tags</title></head><body><h3>This is <em>emphasized</em> and <strong>important</strong> text.</h3></body></html>

    The <sup> and <sub> Tags

    In heading, to include superscript or subscript text within a heading, use <sup> and <sub>.

    <!DOCTYPE html><html><head><title>Using <sup> and <sub> Tags</title></head><body><h4>The 10<sup>th</sup> floor is at the top.</h4><h5>The chemical formula for water is H<sub>2</sub>O.</h5></body></html>

    The <abbr> Tag for Abbreviations

    When you need to include an abbreviation or acronym in a heading, use the <abbr> tag. It often provides a tooltip with the full meaning.

    <!DOCTYPE html><html><head><title>Using <abbr> Tag for Abbreviations</title></head><body><h2>HTML stands for <abbr title="Hypertext Markup Language">HTML</abbr>.</h2></body></html>

    The <br> Tag for Line Breaks

    Sometimes, you might want to create line breaks within a heading for better formatting. The <br> tag serves this purpose.

    <!DOCTYPE html><html><head><title>Using <br> Tag for Line Breaks</title></head><body><h3>This is the first line.<br>This is the second line.</h3></body></html>

    The <mark> Tag

    Use the <mark> tag to highlight specific text within a heading. It's often used to indicate search results or selected portions of text.

    <!DOCTYPE html><html><head><title>Using <mark> Tag</title></head><body><h1>Search for "<mark>important</mark>" information here.</h1></body></html>

    Mistakes to be Avoided

    Make sure we avoid the following mistakes while using the heading tag −

    • Skipping Levels − Always follow the proper hierarchy (h1, h2, h3, etc.). Don't skip levels.
    • Overusing h1 − Reserve h1 for the main title; don't use it multiple times on a page.
    • Styling Overload − Avoid excessive styling; CSS should handle the aesthetics, not headings.