Author: saqibkhan

  • 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:

    Open Compiler

    <!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:

    Open Compiler

    <!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:

    Open Compiler

    <!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:

    Open Compiler

    <!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:

    Open Compiler

    <!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.

    Open Compiler

    <!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.

    Open Compiler

    <!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:

    Open Compiler

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

    Open Compiler

    <!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:

    Open Compiler

    <!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.

    Open Compiler

    <!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>
  • HTML – 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 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 −

    Open Compiler

    <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“.

    Open Compiler

    <!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:

    Open Compiler

    <!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:

    Open Compiler

    <!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:

    Open Compiler

    <!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:

    Open Compiler

    <!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:

    Open Compiler

    <!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
  • HTML – 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:

    Open Compiler

    <!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:

    Open Compiler

    <!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:

    Open Compiler

    <!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:

    Open Compiler

    <!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.

  • HTML – 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

    Open Compiler

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

    Open Compiler

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

  • 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:

    Open Compiler

    <!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:

    Open Compiler

    <!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:

    Open Compiler

    <!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:

    Open Compiler

    <!DOCTYPE html><html><head><title>HTML blockquote tag</title></head><body><h1>wisdompro</h1><p>Here is a quotation from wisdompro official website</p><blockquote cite="https://www.wisdompro.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:

    Open Compiler

    <!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>wisdompro</h1><p>Here is a quotation from wisdompro official website</p><blockquote cite="https://www.wisdompro.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 −

    Open Compiler

    <!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 −

    Open Compiler

    <!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 −

    Open Compiler

    <!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 −

    Open Compiler

    <!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.

  • HTML 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:

    Open Compiler

    <!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:

    Open Compiler

    <!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:

    Open Compiler

    <!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:

    Open Compiler

    <!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:

    Open Compiler

    <!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:

    Open Compiler

    <!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:

    Open Compiler

    <!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:

    Open Compiler

    <!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:

    Open Compiler

    <!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:

    Open Compiler

    <!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:

    Open Compiler

    <!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:

    Open Compiler

    <!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:

    Open Compiler

    <!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:

    Open Compiler

    <!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.
  • HTML 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:

    Open Compiler

    <!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:

    Open Compiler

    <!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.

    Open Compiler

    <!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.

    Open Compiler

    <!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.

    Open Compiler

    <!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>
  • 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.

    Open Compiler

    <!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> −

    Open Compiler

    <!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 −

    Open Compiler

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