Category: Basic

  • Backgrounds

    CSS backgrounds define the background colors and images of HTML elements. They allow you to use different colors, gradients, or images behind the content. In this chapter, we will learn about various CSS background properties, including how to set background colors, apply images, adjust their size and position, control repetition, and more.

    CSS Backgrounds Example

    The following section shows an example of setting color, image, and gradient for an HTML element.

    Background: None

    Background: Color

    Background: Gradient

    Background: Image

    Try Different Background Options

    CSS Background Shorthand Property

    The background shorthand property allows you to specify all background properties in a single declaration.

    The correct order of properties when using the shorthand background property is as follows:

    • background-color
    • background-image
    • background-position
    • background-size (must be used with /)
    • background-repeat
    • background-origin
    • background-attachment
    • background-clip

    Syntax

    The syntax for the background property is as follows:

    background: bg-color bg-image bg-position bg-size bg-repeat bg-origin bg-clip bg-attachment | initial | inherit;/* Example */background: green url('image.jpg') top/20% no-repeat border-box content-box fixed;

    Note: If background-size is to be added, it must be included immediately after the background-position, separated with ‘/’. For example: “left/50%”.

    Setting Background Color

    You can set the background color for elements like div, span, body, paragraph, etc using the background-color property.

    Example

    In this example, we have used three different types of color values for body and div tags. For a complete reference of color in CSS, check out the CSS colors chapter.

    <!DOCTYPE html><html><head><style>  
    
        body {
            background-color: lightgray;
        }
        div{
            padding: 25px;
        }
        .firstDiv{
            background-color: rgb(255, 215, 0);
        }
        .secondDiv{
            background-color: #f0f0f0;
        }
        .thirdDiv{
            background-color: hsl(120, 100%, 75%);
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS Background Colors&lt;/h2&gt;
    Body Color: lightgray; &lt;br&gt;&lt;br&gt;&lt;div class="firstDiv"&gt; Color: rgb(255, 215, 0) &lt;/div&gt;&lt;br&gt;&lt;div class="secondDiv"&gt; Color: #f0f0f0&lt;/div&gt;&lt;br&gt;&lt;div class="thirdDiv"&gt; Color: hsl(120, 100%, 75%)&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Setting Images in Background

    To set an image as background for another element such as div, span, body, paragraph, etc., you can use the background-image property. It can be used to set one or more than one image as the background. To set multiple images as background, we separate the images using commas.

    Example

    In this example, we have set a background image for the body element.

    <!DOCTYPE html><html lang="en"><head><style>
    
        div{
            background-color: rgba(255, 255, 255);
            opacity: 70%;
            padding: 20px;
        }
        body {
            background-image: url(/css/images/logo.png);
            height: 350px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div&gt;&lt;h1&gt;Welcome to My Website&lt;/h1&gt;&lt;p&gt;
            This is an example of setting a 
            background image using CSS
        &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Define Background Position

    The background-position property sets the initial position of the element's background image. The position of the image is relative to the value set by the background-origin property.

    Example

    In this example, we have set the position of the background image to the right of the div element using the background-position property.

    <!DOCTYPE html><html><head><style>  
    
        .position-right {
            background-image: url('/css/images/logo.png');
            background-position: right;
            background-repeat: no-repeat;
            width: 100%;
            height: 300px;
            border: 3px solid black;
            position: relative;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div class="position-right"&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Setting Background Size

    To set the size of the background image of an element, you can use the background-size property. The background image can either be stretched, constrained, or left to its normal size.

    Example

    In this example, we have set the size of the background image to 100% of the div element using the background-size property.

    <!DOCTYPE html><html><head><style>
    
        .size-contain {
            background-image: url('/css/images/pink-flower.jpg');
            background-size: contain; 
            width: 300px;
            height: 300px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS background-size property&lt;/h2&gt;&lt;div class="size-contain"&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Repeating Background Image

    You can control the repetition of the background images using the background-repeat property. The image can be repeated along the horizontal and vertical axes, or not repeated.

    Example

    In this example, we have used the background-repeat property to repeat the background image horizontally and vertically.

    <!DOCTYPE html><html><head><style>
    
        .repeat {
            background-image: url('/css/images/logo.png');
            background-repeat: repeat;
            width: 800px;
            height: 400px;
            position: relative;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt; CSS background-repeat property &lt;/h2&gt;&lt;div class="repeat"&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Defining Background Origin

    CSS background-origin property is used to set the origin of the background, which could be from the start of the border, inside the border, or inside the padding.

    Example

    In this example, we have used the background-origin property to set the origin of the background image to the content box of the div element.

    <!DOCTYPE html><html><head><style>
    
        div {
            border: 10px rgb(13, 7, 190);
            border-style: dashed;
            margin: 5px;
            padding: 1cm;
            font: 700 1em sans-serif;
            color: aliceblue;
            display: inline-block;
            background-image: url('/css/images/yellow-flower.jpg');
            height: 200px;
            width: 200px;
            background-size: contain;
        }
        .content-box {
            background-origin: content-box;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div class="content-box"&gt;&lt;/div&gt;&lt;p&gt; 
        This image background start from content box of 
        div element.
    &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Controlling Background Scrolling

    You can use the background-attachment property to determine whether the position of the background image is fixed within the viewport or scrolls within its container.

    Example

    In this example, we have used the background-attachment property to set the background image to be fixed within the viewport.

    <!DOCTYPE html><html><head><style>
    
        .fixed {
            background-image: url('images/logo.png');
            background-repeat: no-repeat;
            background-attachment: fixed;
            background-position: left top;
            background-color: lightblue;
            background-size: 40% 30%;
            padding: 5rem;
            width: 250px;
            height: 500px;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS background-attachment Property&lt;/h2&gt;&lt;div class="fixed"&gt;&lt;p&gt;
            Lorem Ipsum is simply dummy text of the printing 
            and typesetting industry. Lorem Ipsum has been the 
            industry's standard dummy text ever since the 1500s, 
            when an unknown printer took a galley of type and 
            scrambled it to make a type specimen book. 
            It has survived not only five centuries, but also 
            the leap into electronic typesetting, remaining 
            essentially unchanged. It was popularized in the 
            1960s with the release of Letraset sheets containing 
            Lorem Ipsum passages, and more recently with desktop 
            publishing software like Aldus PageMaker including 
            versions of Lorem Ipsum.
        &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Controlling Background Display

    You can use CSS background-clip property to specify how the background image or color should be displayed within an element's padding box, border box, or content box. It determines the area of an element to which the background will be applied.

    Example

    In this example, we have used the background-clip property to apply the background to the content and padding area of the div element.

    <!DOCTYPE html><html><head><style>
    
        p {
            border: 10px dotted black;
            padding: 15px;
            background: green;
            color: white;
        }
        .border-area {
            background-clip: border-box;
        }
        .padding-area {
            background-clip: padding-box;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;CSS background-clip property&lt;/h2&gt;&lt;p class="border-area"&gt;
        Background applied to the entire element.
    &lt;/p&gt;&lt;p class="padding-area"&gt;
        Background applied to the content &amp; padding area.
    &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Background Properties

    All the properties related to background are listed in the table below:

    PropertyDescriptionExample
    backgroundShorthand for background-related properties.Try It
    background-attachmentSpecifies the position of the background relative to the viewport, either fixed or scrollable.Try It
    background-clipControls how far a background image extends beyond the element's padding or content box.Try It
    background-colorSets the background color of an element.Try It
    background-imageSets one or more background image(s) on an element.Try It
    background-originSets the origin of the background.Try It
    background-positionSets the initial position of each image in a background.Try It
    background-position-xSets the initial horizontal position of each image in a background.Try It
    background-position-ySets the initial vertical position of each image in a background.Try It
    background-repeatControls the repetition of an image in the background.Try It
    background-sizeControls the size of the background image.Try It
    background-blend-modeDetermines how an element's background images blend with each other.Try It

  • Backgrounds

    The background of a webpage is a layer behind its content, which includes text, images, colors, and various other elements.

    It is an essential part of web design that improves the overall look of a web page as well as the user experience. HTML offers multiple attributes and properties for manipulating the background of elements within a document.

    By default, our webpage background is white in color. We may not like it, but no worries. HTML provides the following two good ways to decorate our webpage background:.

    • HTML Background with Colors
    • HTML Background with Images

    Syntax

    The following are the syntaxes for HTML backgrounds:

    <body background = value><body style="background-color: value;">

    The value can be an English name of color, an RGB value of color, or a hexadecimal value of color.

    Examples of HTML Background

    Following are some example codes that show how to set different styles of background for an HTML document.

    Setting Color for Background

    An elementary method to modify the background is by altering its color. The background-color property facilitates the specification of a color for an element’s background. This can be accomplished by incorporating the following style attribute within the opening tag of an HTML element.

    Example

    The following is an example of setting color for background to a DIV:

    <!DOCTYPE html><html lang="en"><head><title>Styled Div Example</title></head><body><div style="background-color: #3498db; "><h1>Welcome to My Website</h1><p>
    
         This is an example of a styled div with a 
         background color and text color.
      &lt;/p&gt;&lt;!-- Additional content goes here --&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Setting Image as Background

    HTML allows us to specify an image as the background of our HTML web page or table. The background and background-image can be used to control the background image of an HTML element, specifically page body and table backgrounds. We simply need to pass the path of an image as a value to both properties as illustrated in the next example. In the below example, the background-image property is assigned to the body of web page.

    Example

    The following is an example of setting an image as a background color; here we are setting an image to the background of the webage with the <body> tag:

    <!DOCTYPE html><html lang="en"><head><title>Background Image Example</title></head><body background="/market/public/assets/newDesign/img/logo.svg"><div style="background-color: rgba(255, 255, 255, 0.8); padding: 20px;"><h1>Welcome to My Website</h1><p>
    
         This is an example of setting a background 
         image using HTML attributes.
      &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Background Repeat and Position

    Although you can set an image as the background using just HTML, in order to control it's behavior, like repeating and positioning, we need to use CSS. We recommend watching our CSS background-image for better understanding. CSS offers options for controlling how background images repeat and their positioning. The background-repeat property specifies whether the image should repeat horizontally, vertically, both, or neither. Furthermore, the background-position property empowers developers to determine where the background image should be positioned within the element.

    Example

    The below HTML program creates a webpage with a centered content div having a repeating vertical background pattern from the specified image. The background color of the container is set to white by default, and the text within the container is styled with a black color, creating a visually appealing and cohesive design.

    <!DOCTYPE html><html lang="en"><head><title>HTML Background Repeat</title><style>
    
      body {
         background-image: 
            url('/market/public/assets/newDesign/img/logo.svg');
         background-repeat: repeat-y;
         background-position: center;
         justify-content: center;
         align-items: center;
         display: flex;
      }
      div{
         background-color: rgba(255, 255, 255, 0.6); 
         padding: 20px;
      }
    </style></head><body><div><h1>Welcome to My Website</h1><p>
         This is an example of setting a background 
         image using HTML attributes.
      &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Setting Patterned Backgrounds

    You might have seen many patterns or transparent backgrounds on various websites. This can simply be achieved by using a patterned image or transparent image in the background. It is suggested that while creating patterns or transparent GIF or PNG images, use the smallest dimensions possible, even as small as 1x1 to avoid slow loading.

    Example

    Here is an example of how to set the background pattern of a table.

    <!DOCTYPE html><html><head><title>HTML Background Images</title></head><body><!-- Set a table background using pattern --><table background = "/images/pattern1.gif" 
    
         width = "100%" 
         height = "100"&gt;&lt;tr&gt;&lt;td&gt;
         This background is filled up with a pattern image.
      &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;!-- Another example on table background using pattern --&gt;&lt;table background = "/images/pattern2.gif" 
         width = "100%" 
         height = "100"&gt;&lt;tr&gt;&lt;td&gt;
         This background is filled up with a pattern image.
      &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;</pre>
  • id

    The id is an important keyword in HTML. HTML “id” is an attribute used to uniquely identify an element within a web page. It serves as a label for that element and enables JavaScript and CSS to target it specifically.

    HTML id attribute is defined in the HTML code using the “id” keyword, and the styling is determined in CSS. This identification helps in applying custom styles, making interactive features, and navigating within the webpage with precision. The “id” values must be unique within the document.

    We highly recommend you to use classes to style any element through CSS..

    Syntax for id

    In CSS, you can target the id attribute by using a hash symbol (#) followed by the id name in HTML element. Try not to use id in CSS rather you can use class attribute. Ids are specially created to execute through JavaScript.

    • In HTML:<element class=”highlight”>…</element>
    • In CSS:/* CSS using id Attribute Selector */#highlight{background-color: yellow;color: black;font-weight: bold;}
    • In JavaScript:document.getElementById(‘highlight’)

    Using HTML id Attribute

    HTML ids are essential for managing events, and changing the structure of documents. In order to create interactive and dynamic web pages, it gives developers the ability to target particular parts and provide them specialized behavior and appearance. Rarely it is used to do the styling in CSS.

    Define a id for Styling

    In the following example, we have create two element one is h1 and other is p, and we set id on them as well “header” & “heightlight” but using the “heightlight” is in internal CSS to style our p element. You can use the “header” id in the similar way to style the h1 element.

    <!DOCTYPE html><html><head><style>
    
      &lt;!-- CSS id attribute Selector Used --&gt;
      #highlight {
         background-color: yellow;
         color: black;
         padding: 5px;
      }
    </style></head><body><!-- Using id attribute in both Element --><h1 id="header">Tutorialspoint</h1><p id="highlight">Simply Easy Learning</p></body></html>

    Using id Attribute through JavaScript

    The ids are frequently used to identify elements for JavaScript functions. For example, you can use a id to target specific elements, like paragraph, and make them interactive through JavaScript. In the following code we have create a button which will trigger a function that will change the display property none to block of a p element. You will see a paragraph.

    <!DOCTYPE html><html><head><script>
    
      function showContent() {
         var element = document.getElementById('content');
         if (element.style.display === 'none') {
            element.style.display = 'block';
         } else {
            element.style.display = 'none';
         }
      }
    </script><style>
      .interactive-button {
         background-color: #007bff;
         color: #fff;
         padding: 10px 20px;
         border: none;
         cursor: pointer;
      }
    </style></head><body><button class="interactive-button"
           onclick="showContent()"&gt;Click Me&lt;/button&gt;&lt;p class="content" style="display: none;"&gt;
       This content can be toggled by clicking the button.
    </p></body></html>

    Difference between id and class in HTML

    In HTML, the id attribute uniquely identifies a single element on a page, making it useful for targeting with CSS and JavaScript, and it must be unique within the document. The class attribute, on the other hand, can be applied to multiple elements, allowing for the grouping of elements that share common styles or behaviors.

    <!DOCTYPE html><html lang="en"><head><title>Difference between id and class</title><style>
    
      /* ID selector */
      #header {
         background-color: blue;
         color: white;
         padding: 10px;
      }
      /* Class selector */
      .button {
         background-color: green;
         color: white;
         padding: 5px 10px;
         margin: 5px;
      }
    </style></head><body><!-- Unique ID for the header --><div id="header">
         This is the header
      &lt;/div&gt;&lt;!-- Shared class for buttons --&gt;&lt;div class="button"&gt;
         Button 1
      &lt;/div&gt;&lt;div class="button"&gt;
         Button 2
      &lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Things to Remember about id

    • The id attribute should contain at least one character should be there, the starting letter should be a character (a-z) or (A-Z), and the rest of the letters of any type can written even special characters.
    • The id attribute does not contain any spaces.
    • Within the document every id must be unique.

    Valid id Attributes Pattern

    Certain ID Attributes are valid in HTML 5, but not in Cascading Style Sheets. In such cases, it is recommended to go with simple output rather than styled output because certain values that we use for ID may be invalid in CSS.

    Following example demonstrates the use of simple ID attributes.

    Example

    If we execute below code, two div elements will be displayed, one with id attribute (TutorialsPoint Website), and the other one with other id attribute (Html5 Tutorials, CSS Tutorials, JavaScript Tutorials).

    <!DOCTYPE html><html><head><title>Simple Id Attributes</title><style>
    
      /* Remove @ from the code and run the code again */
      #@TP {
         color: #070770;
         text-align: center;
         font-size: 30px;
         font-weight: bold;
      }
      #@TP1 {
         text-align: center;
         font-size: 25px;
      }
    </style></head><body><div id="@TP">
      TutorialsPoint Website
    </div><div id="@TP1">
      Html5 Tutorials, CSS Tutorials, JavaScript Tutorials 
    </div></body></html>

    If we remove the @ symbol from the id's value the it will become avalid id declaration and applied styles will be effected on the HTML Element.

  • Classes

    The class is an important keyword in HTML. It is an attribute that can be applied to one or more elements and is used to style and categorize elements based on common characteristics or purpose. Classes allows multiple elements to share the same styling rules. By assigning the same class to multiple elements, you can apply CSS styles or JavaScript functionality to all of them simultaneously. This promotes consistency in design and layout, making it easier to manage and update a website.

    HTML class attribute is defined in the HTML code using the “class” keyword, and the styling is determined in CSS. This separation of content and style is a key principle in web design, facilitating the creation of visually appealing and organized web pages.

    Syntax for Class

    To create a CSS rule for HTML elements using class attribute in CSS write a (.) followed by the class name mentioned in HTML element, the we can define the CSS prpeties with curly braces in key: value; format like color: yellow;.

    In this code, we’ve selected a class named “highlight” that changes the background color, text color, and font weight of the elements it’s applied to.

    • In HTML:<element class=”highlight”>…</element>
    • In CSS:/* CSS using class Attribute Selector */.highlight{background-color: yellow;color: black;font-weight: bold;}
    • In JavaScript:document.getElementsByClassName(‘highlight’)

    Using HTML Class Attribute

    HTML classes are essential for styling and formatting web page elements consistently. They allow you to apply the same styles to multiple elements without repeating code, promoting maintainability and a cohesive design. The class attribute can be used on any HTML Elements(Except elements placed in head element). Here’s how to use classes effectively with a practical example.

    Define a Class for Styling

    In the following example, we have create two element one is h1 and other is p, and we set class on them as well “header” & “heightlight” but using the “heightlight” class in internal CSS to style our p element. You can use the “header” class in the similar way to style the h1 element.

    <!DOCTYPE html><html><head><style><!-- CSS class attribute Selector Used -->
    
      .highlight {
         background-color: yellow;
         color: black;
         padding: 5px;
      }
    </style></head><body><!-- Using class attribute in both Element--><h1 class="header">Tutorialspoint</h1><p class="highlight">Simply Easy Learning</p></body></html>

    Multiple classes

    We can apply multiple classes to a single element by separating class names with a space.

    In the following example, the <h1> element has two classes applied “heading” and “content.” This is achieved using a space to separate the class names within the class attribute.

    Multiple classes can be applied to the same element to inherit styling from both classes. In this case, “heading” class provides a large font size and center alignment, while the “content” class provides a specific text color and line-height.

    <!DOCTYPE html><html><head><style>
    
        .heading {
            font-size: 24px;
            color: #333;
            text-align: center;
        }
        .content {
            font-size: 16px;
            color: #666;
            line-height: 1.5;
        }
        .button {
            background-color: #007bff;
            color: #fff;
            padding: 10px 20px;
            border: none;
            cursor: pointer;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;!-- Defined two Classes in h1 Element --&gt;&lt;h1 class="heading content"&gt;
        Welcome to Tutorialspoint
    &lt;/h1&gt;&lt;p class="content"&gt;
        We make Tutorials - Simply Easy Learning
    &lt;/p&gt;&lt;button class="button"&gt;Click Me&lt;/button&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Same class on Multiple Elements

    The most important feature of classes is their reusability. You can apply the same class to multiple elements to maintain a consistent look throughout your website. Here in the following example we create 2 p elements(paragraphs). Both of these paragraphs will have the same highlighting because they share the "highlight" class.

    <!DOCTYPE html><html><head><style>
    
      .highlight {
         background-color: yellow;
         color: black;
         font-weight: bold;
      }
    </style></head><body><p class="highlight">
      To create a class, you need to define it within
      your HTML document or link to an external CSS 
      file that contains class definitions. Classes 
      are defined using the "class" attribute.
    </p><p class="highlight">
      HTML classes are essential for styling and formatting
      web page elements consistently. They allow you to apply
      the same styles to multiple elements without repeating 
      code, promoting maintainability and a cohesive design.
    </p></body></html>

    Using class Attribute through JavaScript

    HTML classes are versatile and serve various purposes beyond styling.

    The classes are frequently used to identify elements for JavaScript functions. For example, you can use a class to target specific elements, like buttons, and make them interactive through JavaScript. In the following code we have create a button which will trigger a function that will change the display property none to block of a p element. You will see a paragraph.

    <!DOCTYPE html><html><head><script>
    
      function showContent() {
         var element = document.getElementsByClassName('content')[0];
         if (element.style.display === 'none') {
            element.style.display = 'block';
         } else {
            element.style.display = 'none';
         }
      }
    </script><style>
      .interactive-button {
         background-color: #007bff;
         color: #fff;
         padding: 10px 20px;
         border: none;
         cursor: pointer;
      }
    </style></head><body><button class="interactive-button"
           onclick="showContent()"&gt;Click Me&lt;/button&gt;&lt;p class="content" style="display: none;"&gt;
       This content can be toggled by clicking the button.
    </p></body></html>

    Things to Remember about Class

    • More than 1 class can be define on any HTML element.
    • Class are used by CSS and JavaScript both to select the element.
    • The class is case sensitive so be careful when you are using to select the element.
    • Multiple elements can have the same class as well.
    • In CSS we use .className and in JavaScript getElementsByClassName() method to select the class assigned HTML element.
  • Meta Tags

    HTML <meta> tag lets us specify metadata, which is additional important information about a document, in a variety of ways. The META elements can be used to include name and content pairs describing properties of the HTML document, such as author, expiry date, a list of keywords, document author, etc.

    HTML <meta> tag can be used to provide extra information. It’s a self-closing element, meaning it doesn’t require a closing tag but carries information within its attributes. You can include one or more meta tags in your document based on what information you want to keep in your document, but in general, meta tags do not impact the physical appearance of the document, so from the appearance point of view, it does not matter if you include them or not.

    Adding Metadata to Web Pages Using Meta Tags

    You can add metadata to your web pages by placing <meta> tags inside the header of the document, which is represented by the <head> tag.

    The following metadata can be added using the <meta> tag:

    Below, you can check all the examples that are well described with the code for how we should use individuals on our website.

    Specifying Keywords

    You can use the <meta> tag to specify important keywords related to the document, and later these keywords are used by the search engines while indexing your webpage for searching purposes.

    Example

    Following is an example where we are adding “HTML, Meta Tags, and Metadata” as important keywords about the document:

    <!DOCTYPE html><html><head><title>Meta Tags Example</title><meta name="keywords" content="HTML, Meta Tags, Metadata" /></head><body><p>Hello HTML5!</p></body></html>

    Document Description

    You can use the <meta> tag to give a short description about the document. This again can be used by various search engines while indexing your webpage for searching purposes.

    Example

    The following example demonstrates how you can define a meta description for a webpage:

    <!DOCTYPE html><html><head><title>Meta Tags Example</title><meta name="keywords" content="HTML, Meta Tags, Metadata" /><meta name="description" content="Learning about Meta Tags." /></head><body><p>Hello HTML5!</p></body></html>

    Document Revision Date

    You can use the <meta> tag to give information about the last time the document was updated. This information can be used by various web browsers while refreshing your webpage.

    Example

    The following example demonstrates how you can define a revision date:

    <!DOCTYPE html><html><head><title>Meta Tags Example</title><meta name="keywords" content="HTML, Meta Tags, Metadata" /><meta name="description" content="Learning about Meta Tags." /><meta name="revised" content="Tutorialspoint, 3/7/2014" /></head><body><p>Hello HTML5!</p></body></html>

    Document Refreshing

    The <meta> tag can be used to specify a duration after which your web page will keep refreshing automatically.

    Example

    If you want your page to keep refreshing after every 5 seconds, then use the following syntax:

    <!DOCTYPE html><html><head><title>Meta Tags Example</title><meta name="keywords" content="HTML, Meta Tags, Metadata" /><meta name="description" content="Learning about Meta Tags." /><meta name="revised" content="Tutorialspoint, 3/7/2014" /><meta http-equiv="refresh" content="5" /></head><body><p>Hello HTML5!</p></body></html>

    Page Redirection

    You can use the <meta> tag to redirect your page to any other webpage. You can also specify a duration if you want to redirect the page after a certain number of seconds.

    Example

    Following is an example of redirecting the current page to another page after 5 seconds. If you want to redirect the page immediately, then do not specify the content attribute:

    <!DOCTYPE html><html><head><title>Meta Tags Example</title><meta name="keywords" content="HTML, Meta Tags, Metadata" /><meta name="description" content="Learning about Meta Tags." /><meta name="revised" content="Tutorialspoint, 3/7/2014" /><meta http-equiv="refresh" content="5; url=http://www.tutorialspoint.com" /></head><body><p>Hello HTML5!</p></body></html>

    Setting Cookies

    Cookies are data stored in small text files on your computer, and it is exchanged between a web browser and a web server to keep track of various information based on your web application needs.

    You can use the <meta> tag to store cookies on the client side, and later this information can be used by the Web server to track a site visitor. If you do not include the expiration date and time, the cookie is considered a session cookie and will be deleted when the user exits the browser.

    Example

    Following is an example of redirecting the current page to another page after 5 seconds. If you want to redirect the page immediately, then do not specify the content attribute.

    <!DOCTYPE html><html><head><title>Meta Tags Example</title><meta name="keywords" content="HTML, Meta Tags, Metadata" /><meta name="description" content="Learning about Meta Tags." /><meta name="revised" content="Tutorialspoint, 3/7/2014" /><meta http-equiv="cookie" content="userid=xyz; expires=Wednesday, 08-Aug-15 23:59:59 GMT;" /></head><body><p>Hello HTML5!</p></body></html>

    Note: You can check the PHPand Cookies tutorial for a complete detail on cookies.

    Setting Author Name

    You can set an author name on a web page using a <meta> tag. Author name be specified by assigning the “author” value to the “name” attribute.

    Example

    The following example demonstrates how you can set an author name:

    <!DOCTYPE html><html><head><title>Meta Tags Example</title><meta name="keywords" content="HTML, Meta Tags, Metadata" /><meta name="description" content="Learning about Meta Tags." /><meta name="author" content="Mahnaz Mohtashim" /></head><body><p>Hello HTML5!</p></body></html>

    Specify Character Set

    You can use the <meta> tag to specify the character set used within the webpage. By default, Web servers and Web browsers use ISO-8859-1 (Latin1) encoding to process Web pages.

    Example

    Following is an example to set UTF-8 encoding:

    <!DOCTYPE html><html><head><title>Meta Tags Example</title><meta name="keywords" content="HTML, Meta Tags, Metadata" /><meta name="description" content="Learning about Meta Tags." /><meta name="author" content="Mahnaz Mohtashim" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body><p>Hello HTML5!</p></body></html>

    Example

    To serve the static page with traditional Chinese characters, the webpage must contain a <meta> tag to set Big5 encoding:

    <!DOCTYPE html><html><head><title>Meta Tags Example</title><meta name="keywords" content="HTML, Meta Tags, Metadata" /><meta name="description" content="Learning about Meta Tags." /><meta name="author" content="Mahnaz Mohtashim" /><meta http-equiv="Content-Type" content="text/html; charset=Big5" /></head><body><p>Hello HTML5!</p></body></html>
  • Code Elements

    HTML computer code elements (tags) provide unique formatting and text styles for different types of code-related messages, such as keyboard input, preformatted text, code snippets, variables, and sample outputs. The computer code elements are listed as follows:

    HTML <kbd> Element

    The <kbd> tag is used to define the keyboard input. Use this when you want the user to type on their keyboard, for example, shortcut keys Ctrl+C for copy, Esc for exit, etc.

    Example

    Let us now see an example to implement the <kbd> tag:

    <!DOCTYPE html><html><body><h2>Example of kbd Tag</h2><p>Use the following shortcut keys:</p><p><strong>Cut</strong><kbd>CTRL</kbd>+<kbd>X</kbd></p><p><strong>Copy</strong><kbd>CTRL</kbd>+<kbd>C</kbd></p><p><strong>Paste</strong><kbd>CTRL</kbd>+<kbd>V</kbd></p><p><strong>Undo</strong><kbd>CTRL</kbd>+<kbd>Z</kbd></p></body></html>

    HTML <pre> Element

    The <pre> tag in HTML is used to set preformatted text. The text preserves spaces and line breaks, appearing the same on the web page as in the HTML code.

    Example

    Let us now see an example to implement the <pre> tag:

    <!DOCTYPE html><html><body><h2>Example of pre Tag</h2><pre>
      This is a demo text
      and will appear
      in the same format as
      it
      is visible
      here. The pre tag displays
      the text in a fixed-width
      font. It preserves
      both spaces and
      line breaks as you can see
      here.
    </pre></body></html>

    HTML <code> Element

    The <code> tag is used to format code in an HTML document. For example, to write and format Java code properly, use the <code> element.

    Example

    Let us now see an example to implement the <code> element:

    <!DOCTYPE html><html><body><h1>Example of code Tag</h1><h2>C++</h2><code>
    
         #include 
         &lt;iostream&gt;&lt;/code&gt;&lt;h2&gt;C&lt;/h2&gt;&lt;code&gt;
         #include 
         &lt;stdio.h&gt;&lt;/code&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    HTML <var> Element

    The <var> tag in HTML is used to display mathematical expressions for calculations.

    Example

    Let us now see an example to implement the <var> tag:

    <!DOCTYPE html><html><body><h2>Example of var Tag</h2>
    
      Sample equation  &lt;var&gt;2x&lt;/var&gt; - &lt;var&gt;2z&lt;/var&gt; = &lt;var&gt;3y&lt;/var&gt; + 9
    </body></html>

    HTML <samp> Element

    The <samp> tag is a phrase tag used to format text in an HTML document.

    Example

    Let us now see an example to implement the <samp> element:

    <!DOCTYPE html><html><body><h2>Exam Results</h2><p><s>Result would be announced on 6th June.</s></p><samp>New date for results is 7th June.</samp></body></html>

    HTML Computer Code Elements

    Here is the list of the computer code tags along with their descriptions used for defining user input and computer code:

    TagDescription
    <kbd>Defines keyboard input.
    <pre>Displays preformatted text with preserved spaces and line breaks.
    <code>Defines a piece of computer code.
    <var>Represents a variable in programming or math expressions.
    <samp>Defines sample output from a program or device.
  • Phrase Tags

    HTML phrase tags have been designed for specific purposes, though they are displayed in a similar way as other basic tags like <b>, <i>, <pre>, and <tt>. Here we will take you through all the important phrase tags; so let’s start seeing them one by one. Following is the list of phrase tags, some of them are discussed in HTML formatting and quotations.

    HTML Phrase Tags List

    • Emphasized Text – HTML em Tag
    • Marked Text – HTML mark Tag
    • Strong Text – HTML strong Tag
    • Abbreviation Text – HTML abbr Tag
    • Acronym Text – HTML acronym Tag
    • Directed Text – HTML bdo Tag
    • Special Terms – HTML dfn Tag
    • Short Quoting Text – HTML q tag
    • Long Quoting Text – HTML blockquote Tag
    • Citations Text – HTML cite Text
    • Computer Code Text – HTML code Tag
    • Keyboard Text – HTML kbd Text
    • Programming Variables – HTML pre Tag
    • Program Output – HTML samp Tag
    • Address Text – HTMl address Tag

    Below we have used each tags of phrase tags, each tag has it’s default styling few of them accepts some attributes as well.

    Emphasized Text

    Content that is enclosed within the <em>…</em> element is displayed as emphasized text. The <em> element typically renders text in italics, indicating emphasis.

    Example

    <!DOCTYPE html><body><p>The following word uses a <em>emphasized</em> typeface.</p></body></html>

    Output

    The following word uses a emphasized typeface.
    

    Marked Text

    Anything that is enclosed within the <mark>…</mark> element is displayed as marked with yellow ink.

    Example

    <!DOCTYPE html><html><body><p>The following word has been <mark>marked</mark> with yellow.</p></body></html>

    Output

    The following word has been marked with yellow.
    

    Strong Text

    Content that is enclosed within the <strong>…</strong> element is displayed as important text. The <strong> element displays text in a bold font, indicating strong importance.

    Example

    <!DOCTYPE html><html><body><p>The following word uses a <strong>strong</strong> typeface. </p></body></html>

    Output

    The following word uses a strong typeface.
    

    Abbreviation Text

    You can abbreviate a text by putting it inside opening <abbr> and closing </abbr> tags. If present, the title attribute must contain this full description and nothing else.

    Example

    <!DOCTYPE html><html><body><p>My best friend's name is <abbr title="Abhishek">Abhy</abbr>. </p></body></html>

    Output

    My best friend's name is Abhy.
    

    Acronym Text

    The <acronym> element allows you to indicate that the text between <acronym> and </acronym> tags is an acronym.

    At present, the major browsers do not change the appearance of the content of the <acronym> element.

    The <acronym> element is deprecated in HTML5. Instead, you should use the <abbr> element to define abbreviations, and you can specify the full description using the “title” attribute.

    Example

    <!DOCTYPE html><html><body><p>This chapter covers marking up text in <acronym>XHTML</acronym>. </p></body></html>

    Output

    This chapter covers marking up text in XHTML.
    

    Directed Text

    The <bdo>…</bdo> element stands for Bi-Directional Override, and it is used to override the current text direction.

    Example

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

    Output

    This text will go right to left.
    

    Special Terms

    The <dfn>…</dfn> element (or HTML Definition Element) allows you to specify that you are introducing a special term. Its usage is similar to italic words in the midst of a paragraph.

    Typically, you would use the <dfn> element the first time you introduce a key term. Most recent browsers render the content of a <dfn> element in an italic font.

    Example

    <!DOCTYPE html><html><body><p>The following word is a <dfn>special</dfn> term. </p></body></html>

    Output

    The following word is a special term.
    

    Quoting Text

    When you want to quote a passage from another source, you should put it in between <blockquote>…</blockquote> tags.

    Text inside a <blockquote> element is usually indented from the left and right edges of the surrounding text and sometimes uses an italicized font.

    Example

    <!DOCTYPE html><html><body><p>The following description of XHTML is taken from the W3C Web site:</p><blockquote>XHTML 1.0 is the W3C's first Recommendation for XHTML, following on from earlier work on HTML 4.01, HTML 4.0, HTML 3.2 and HTML 2.0.</blockquote></body></html>

    Output

    The following description of XHTML is taken from the W3C Web site:
    XHTML 1.0 is the W3C's first Recommendation for XHTML, following on 
    from earlier work on HTML 4.01, HTML 4.0, HTML 3.2 and HTML 2.0.
    

    Short Quotations

    The <q>…</q> element is used when you want to add a double quote within a sentence. By using <q>…</q>, you ensure that the enclosed text is presented as a direct quotation, enhancing readability and maintaining proper punctuation in your HTML document.

    Example

    <!DOCTYPE html><html><body><p>Amit is in Spain, <q>I think I am wrong</q>. </p></body></html>

    Output

    Amit is in Spain, I think I am wrong.
    

    Text Citations

    If you are quoting a text, you can indicate the source by placing it between an opening <cite>tag and closing </cite> tag.

    As you would expect in a print publication, the content of the <cite> element is rendered in italicized text by default.

    Example

    <!DOCTYPE html><html><body><p>This HTML tutorial is derived from <cite>W3 Standard for HTML</cite>. </p></body></html>

    Output

    This HTML tutorial is derived from W3 Standard for HTML.
    

    Computer Code

    Any programming code to appear on a Web page should be placed inside <code>…</code> tags. Usually the content of the <code> element is presented in a monospaced font, just like the code in most programming books.

    Example

    <!DOCTYPE html><html><body><p>Regular text. <code>This is code.</code> Regular text. </p></body></html>

    Output

    Regular text. This is code. Regular text.
    

    Keyboard Text

    When you are talking about computers, if you want to tell a reader to enter some text, you can use the <kbd>…</kbd> element to indicate what should be typed in, as in this example.

    Example

    <!DOCTYPE html><html><body><p>Regular text. <kbd>This is inside kbd element</kbd> Regular text. </p></body></html>

    Output

    Regular text. This is inside kbd element Regular text.
    

    Programming Variables

    The <var> element is usually used in conjunction with the <pre> and <code> elements to indicate that the content of that element is a variable.

    Example

    <!DOCTYPE html><html><body><p><code>document.write(" <var>user-name</var>") </code></p></body></html>

    Output

    document.write(" user-name") 

    Program Output

    The <samp>…</samp> element indicates sample output from a program, and script, etc. Again, it is mainly used when documenting programming or coding concepts.

    Example

    <!DOCTYPE html><html><body><p>Result produced by the program is <samp>Hello World!</samp></p></body></html>

    Output

    Result produced by the program is Hello World!
    

    Address Text

    The <address>…</address> element is used to contain any address.

    Example

    <!DOCTYPE html><html><body><address>388A, Road No 22, Jubilee Hills - Hyderabad</address></body></html>

    Output

    388A, Road No 22, Jubilee Hills - Hyderabad
    
  • Iframes

    HTML iframe is an inline frame that allows you to embed another document within the current HTML document. Whenever you want to display another webpage within the webpage, you can use an iframe. 

    Creating iframe (Inline Frame)

    In HTML, the inline frame is defined with the <iframe> tag. This tag creates a rectangular region at a specified place within the HTML document in which the browser can display an external document such as a map or another web page.

    Iframe Syntax

    The following is the syntax to create an inline frame (iframe) in HTML:

    <iframe src="url" title="description"></iframe>

    The src Attribute

    The URL or path of the external document is attached using the src attribute of the <iframe> tag. If the content of the iframe exceeds the specified rectangular region, HTML automatically includes the scrollbars. HTML allows any number of iframes, but it may affect the performance of the website.

    Iframe Example

    The following example demonstrates how you can create an iframe in HTML:

    <!DOCTYPE html><html><head><title>HTML Iframes</title></head><body><p>It is an example of HTML Iframe</p><iframe src="/html/menu.htm"> Sorry your browser does not support inline frames. </iframe></body></html>

    The <iframe> Tag Attributes

    The following table describe the attributes used with the <iframe> tag.

    S.No.Attribute & Description
    1srcThis attribute is used to give the file name that should be loaded in the frame. Its value can be any URL. For example, src=”/html/top_frame.htm” will load an HTML file available in html directory.
    2nameThis attribute allows to give a name to a specific frame. It is used to indicate which frame a document should be loaded into. This is important when you want to create links in one frame that load pages into an another frame, in which case the second frame needs a name to identify itself as the target of the link.
    3heightThis attribute specifies the height of <iframe>. By default it is 150 pixels.
    4widthThis attribute specifies the width of <iframe>. By default it is 300 pixels.
    5allowIt is used to specify the permission policies to access features like microphone and camera.
    6loadingIt specifies the time to load a given iframe.

    Setting Height and Width of Iframes

    You can set the height and width of an HTML iframe by using the height and width attributes of the <iframe> tag.

    Example

    The following example demonstrates how you can set the height and width of an iframe:

    <!DOCTYPE html><html><head><title>HTML Iframes</title></head><body><h2>Example of Setting Height and width of HTML Iframe</h2><iframe src="/index.htm" width="500" height="300"> 
    
    Sorry your browser does not support inline frames. 
    &lt;/iframe&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    The above code will display the "index.htm" webpage in an iframe with the specified height and width.

    Linking to an Iframe: Target and Name Attributes

    You can use an iframe as a target frame to open a webpage on clicking a link.

    You can create a target iframe for a link (hyperlink) by using the name attribute of the <iframe> tag. The value of the name attribute is used in the target attribute of elements like <form> and <a> to specify the target frame.

    Example

    The following example demonstrates how you can make a target iframe for a hyperlink:

    <!DOCTYPE html><html><head><title>HTML Iframes</title></head><body><h2>Linking to an Iframe: Target and Name Attributes</h2><p>Click on the link below to load the content inside the specified frame...</p><p><a href="/html/html_iframes.htm" target="Iframe">
    
      Iframe Tutorial
      &lt;/a&gt;&lt;/p&gt;&lt;iframe style="background-color: skyblue;" name="Iframe" width="500" height="300"&gt;
    Sorry your browser does not support inline frames.
    &lt;/iframe&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    On execution, the above code will generate a link and an Iframe with a sky-blue background. When the link is clicked, its content will open inside the iframe.

    Styling Iframe

    You can also use the style or class attributes to apply the CSS rules on an iframe.

    Example

    The following example demonstrates how you can apply CSS styles to an iframe:

    <!DOCTYPE html><html><head><title>HTML Iframes</title><style type="text/css">
    
      body{
        background-color: #FFF4A3;
      }
      .my_iframe{
        width: 90%;
        height: 180px;
        border: 2px solid #f40;
        padding: 8px;
      }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;Example of Styling Iframe&lt;/h2&gt;&lt;iframe src="/index.htm" class="my_iframe"&gt; 
    Sorry your browser does not support inline frames. 
    &lt;/iframe&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Multiple Iframes

    You can embed multiple documents (webpages) within a webpage. HTML allows you to use multiple <iframe> tags in an HTML document.

    Note: Use of multiple iframes may slow down your page loading speed.

    Example

    In the following example, we are embedding three webpages using multiple iframes:

    <!DOCTYPE html><html><head><title>HTML Iframes</title><style type="text/css">
    
      body{
        background-color: #FFF4A3;
      }
      .my_iframe{
        width: 90%;
        height: 180px;
        border: 2px solid #f40;
        padding: 8px;
        margin-bottom: 8px;
      }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h2&gt;Example of Multiple Iframes&lt;/h2&gt;&lt;h3&gt;Index Page&lt;/h3&gt;&lt;iframe src="/index.htm" class="my_iframe"&gt; 
    Sorry your browser does not support inline frames. 
    &lt;/iframe&gt;&lt;h3&gt;Tutorials Library&lt;/h3&gt;&lt;iframe src="/tutorialslibrary.htm" class="my_iframe"&gt; 
    Sorry your browser does not support inline frames. 
    &lt;/iframe&gt;&lt;h3&gt;Compilers&lt;/h3&gt;&lt;iframe src="/codingground.htm" class="my_iframe"&gt; 
    Sorry your browser does not support inline frames. 
    &lt;/iframe&gt;&lt;/body&gt;&lt;/html&gt;</pre>
  • Frames

    HTML frames are used to divide your browser window into multiple sections where each section can load a separate HTML document independently. A collection of frames in the browser window is known as a frameset. The window is divided into frames in a similar way the tables are organized: into rows and columns.

    The <frame> tag is no longer recommended as it is not supported by HTML5. Instead of using this tag, we can use the <iframe> or <div> with CSS to achieve the similar effects.

    Syntax

    <frameset rows="50%,50%"><frame name="top" src="link/to/frame1" /><frame name="bottom" src="link/to/frame2" /></frameset>

    Where the rows attribute of frameset defines the division of the window into horizontal sections. In this case, the window is divided into two rows, each taking up 50% of the available height.

    Examples of HTML Frames

    Here are some example codes that illustrate how to manipulate frames in HTML.

    Creating Frames in HTML

    To make frames on a page we use <frameset> tag instead of <body> tag. The <frameset> tag defines how to divide the window into frames. The rows attribute of <frameset> tag defines horizontal frames and cols attribute defines vertical frames. Each frame is indicated by <frame> tag and it defines which HTML document shall open into the frame.

    Following is the example to create three horizontal frames. If your browser does not support frames, then body element is displayed.

    <!DOCTYPE html><html><head><title>HTML Frames</title></head><frameset rows="10%,80%,10%"><frame name="top" src="/html/top_frame.htm" /><frame name="main" src="/html/main_frame.htm" /><frame name="bottom" src="/html/bottom_frame.htm" /><noframes><body>
    
         Your browser does not support frames.
      &lt;/body&gt;&lt;/noframes&gt;&lt;/frameset&gt;&lt;/html&gt;</pre>

    Creating vertical Frames

    Here we replaced rows attribute by cols and changed their width. This will create all the three frames vertically.

    <!DOCTYPE html><html><head><title>HTML Frames</title></head><frameset cols="25%,50%,25%"><frame name="left" src="/html/top_frame.htm" /><frame name="center" src="/html/main_frame.htm" /><frame name="right" src="/html/bottom_frame.htm" /><noframes><body>
    
         Your browser does not support frames.
      &lt;/body&gt;&lt;/noframes&gt;&lt;/frameset&gt;&lt;/html&gt;</pre>

    Frame's name and target Attributes

    One of the most popular uses of frames is to place navigation bars in one frame and then load main pages into a separate frame.

    Let's see following example where a test.htm file has following code:

    <!DOCTYPE html><html><head><title>HTML Target Frames</title></head><frameset cols="200, *"><frame src="/html/menu.htm" name="menu_page" /><frame src="/html/main.htm" name="main_page" /><noframes><body>
       Your browser does not support frames.
    </body></noframes></frameset></html>

    Here we have created two columns to fill with two frames. The first frame is 200 pixels wide and will contain the navigation menubar implemented by menu.htm file. The second column fills in remaining space and will contain the main part of the page and it is implemented by main.htm file. For all the three links available in menubar, we have mentioned target frame as main_page, so whenever you click any of the links in menubar, available link will open in main_page.

    Following is the content of menu.htm file

    <!DOCTYPE html><html><body bgcolor="#4a7d49"><a href="https://www.google.com" target="main_page">
    
      Google
    </a><br /><br /><a href="https://www.microsoft.com" target="main_page">
      Microsoft
    </a><br /><br /><a href="https://news.bbc.co.uk" target="main_page">
      BBC News
    </a></body></html>

    Following is the content of main.htm file:

    <!DOCTYPE html><html><body bgcolor="#b5dcb3"><h3>
    
      This is main page and content from any link 
      will be displayed here.
    </h3><p>
      So now click any link and see the result.
    </p></body></html>

    Attributes of frameset Tag

    Below listed attributes are accepted by frameset tag.

    AttributesDescription
    colsSpecifies how many columns are contained in the frameset and the size of each column. You can specify the width of each column in one of four ways.Absolute values in pixels. For example to create three vertical frames, use cols="100, 500,100".A percentage of the browser window. For example to create three vertical frames, use cols="10%, 80%,10%".Using a wildcard symbol. For example to create three vertical frames, use cols="10%, *,10%". In this case wildcard takes remainder of the window.As relative widths of the browser window. For example to create three vertical frames, use cols="3*,2*,1*". This is an alternative to percentages. You can use relative widths of the browser window. Here the window is divided into sixths: the first column takes up half of the window, the second takes one third, and the third takes one sixth.
    rowsThis attribute works just like the cols attribute and takes the same values, but it is used to specify the rows in the frameset. For example to create two horizontal frames, use rows="10%, 90%". You can specify the height of each row in the same way as explained above for columns.
    borderThis attribute specifies the width of the border of each frame in pixels. For example border="5". A value of zero means no border.
    frameborderThis attribute specifies whether a three-dimensional border should be displayed between frames. This attribute takes value either 1 (yes) or 0 (no). For example frameborder="0" specifies no border.
    framespacingThis attribute specifies the amount of space between frames in a frameset. This can take any integer value. For example framespacing="10" means there should be 10 pixels spacing between each frames.

    HTML <frame> Tag Attributes

    Below listed arrtibutes are accepted by the frame tag.

    AttributeDescription
    srcThis attribute is used to give the file name that should be loaded in the frame. Its value can be any URL. For example, src="/html/top_frame.htm" will load an HTML file available in html directory.
    nameThis attribute allows you to give a name to a frame. It is used to indicate which frame a document should be loaded into. This is especially important when you want to create links in one frame that load pages into an another frame, in which case the second frame needs a name to identify itself as the target of the link.
    frameborderThis attribute specifies whether or not the borders of that frame are shown; it overrides the value given in the frameborder attribute on the <frameset> tag if one is given, and this can take values either 1 (yes) or 0 (no).
    marginwidthThis attribute allows you to specify the width of the space between the left and right of the frame's borders and the frame's content. The value is given in pixels. For example marginwidth="10".
    marginheightThis attribute allows you to specify the height of the space between the top and bottom of the frame's borders and its contents. The value is given in pixels. For example marginheight="10".
    noresizeBy default you can resize any frame by clicking and dragging on the borders of a frame. The noresize attribute prevents a user from being able to resize the frame. For example noresize="noresize".
    scrollingThis attribute controls the appearance of the scrollbars that appear on the frame. This takes values either "yes", "no" or "auto". For example scrolling="no" means it should not have scroll bars.
    longdescThis attribute allows you to provide a link to another page containing a long description of the contents of the frame. For example longdesc="framedescription.htm"

    Disadvantages of Frames

    There are few drawbacks with using frames, so it's never recommended to use frames in your webpages.

    • Some smaller devices cannot cope with frames often because their screen is not big enough to be divided up.
    • Sometimes your page will be displayed differently on different computers due to different screen resolution.
    • The browser's back button might not work as the user hopes.
    • There are still few browsers that do not support frame technology.
  • Image Map

    Image Maps

    HTML image maps are defined by the <map> tag. An image map enables specific areas of an image to be clickable, acting as links to different destinations. This technique is useful for creating complex navigation systems or interactive graphics on a webpage.

    By defining various shapes (rectangles, circles, and polygons) within an image, each with its own associated link, developers can create dynamic and interactive visual content that enhances user engagement and navigation.

    Use of Image Maps

    Image maps are useful for creating complex navigation, interactive diagrams, or engaging visual experiences, enhancing user engagement and interactivity on web pages.

    It is useful to create interactive graphics by defining clickable regions within an image. This allows users to interact with different image parts, triggering specific actions or links.

    HTML <map> Tag

    The <map> tag is used to create a client-side image map, turning specific regions of an image into interactive elements. This allows users to click on different areas of the image, triggering various actions. The <map> element serves as a container for <area> elements, each defining a clickable region with specific attributes.

    Syntax

    The following is the syntax of the <map> tag:

    <map name="world map"><!-- Define your clickable areas here --></map>

    When used in conjunction with the <img> tag, the <map> tag establishes a connection between the image and its associated map. This enables web developers to create dynamic and interactive content by defining distinct clickable zones within an image.

    Defining Areas (Shapes) in Image Maps

    The <area> tag is used within the <map> tag to define clickable regions on an image. It specifies the shape, coordinates, and associated actions for each clickable area.

    Following is the syntax of the <area> tag −

    <area shape="shape_values" coords="coordinates" href="url" alt="Description">

    1. Rectangular Area

    You can define a rectangular shape by assigning the rect value to the shape attribute. The rectangular shape requires coordinates for the top-left and bottom-right corners that you can define in coords attribute.

    Syntax

    <area shape="rect" coords="x1,y1,x2,y2" href="url" alt="Description">
    • x1, y1 − Coordinates of the top-left corner.
    • x2, y2 − Coordinates of the bottom-right corner.

    2. Circular Area

    You can define a circular shape by assigning the circle value to the shape attribute. The circular shape requires center coordinates (xy) and radius (r) that you can define in coords attribute.

    <area shape="circle" coords="x,y,r" href="url" alt="Description">
    • x, y − Coordinates of the circle’s center.
    • r − Radius of the circle.

    3. Polygon Area

    You can define a polygon shape by assigning the poly value to the shape attribute. The polygon shape requires a series of coordinates to form the shape that you can define in coords attribute.

    This can be used to create any shape, whether it be a mango or apple.

    Syntax

    <area shape="poly" coords="x1,y1,x2,y2,..,xn,yn" href="url" alt="Description">

    Where x1, y1,..., xn, yn coordinates form the polygon.

    These shapes enable the creation of interactive image maps, enhancing user engagement by associating distinct actions with specific areas within an image.

    Creating an Image Map in HTML

    To create an image map in HTML, follow these steps with a code example −

    Step 1: Prepare Your Image

    Begin with the image you want to use as an image map. For this example, we’ll use an image file named logo.png.

    Use the usemap attribute in the <img> tag to link the image to the <map> tag by keeping its value to the name attribute of the <map>:

    <img src="/images/logo.png" usemap="#image_map">

    Step 2: Define the Image Map

    Use the <map> tag to define the image map and give it a unique name with the name attribute.

    <map name="image_map"></map>

    Step 3: Define Clickable Areas

    Within the <map> element, define clickable areas using <area> tags. Specify the shape (rectcircle, or poly), coordinates, and the URL to link to.

    <map name="image_map"><area shape="circle" coords="45,32,49" href="index.htm" alt="tutorialspoint"><area shape="rect" coords="245,50,85,9" href="/tutorialslibrary.htm" alt="tutorials_library"></map>

    Repeat Step 3 for each clickable area you want to create within the image. Finally, close the HTML file and save it with the .html extension.

    Example of HTML Image Map

    This example creates an HTML image map where specific areas on the image (logo.png) link to different pages using the <area> tags within the <map> element.

    <!DOCTYPE html><html><head><title>Image Map Example</title></head><body><img src="/images/logo.png" usemap="#image_map"><map name="image_map"><!-- Define your clickable areas here --><area shape="circle" coords="45,32,49" href="/index.htm" alt="tutorialspoint"><area shape="rect" coords="245,50,85,9" href="/tutorialslibrary.htm" alt="tutorials_library"></map></body></html>