How to define media type of style tag in HTML5?

Within the realm of web development, comprehending the subtle distinctions between styling and designing is pivotal in the creation of web pages that are aesthetically pleasing and exceedingly efficient. In HTML5, determining the media classification of style tags is a fundamental component of this process, enabling developers to specify the nature of device or media on which their styles shall be implemented. Though the notion of media classification may appear intricate, mastering this art is indispensable for web developers who yearn to develop dynamic and receptive web designs. In this composition, we shall delve into the intricacies of determining media classifications in HTML5 style tags, exploring the underlying structure as well as the diverse categories of media that can be targeted.


To prescribe the multimedia genre of a style tag in HTML5, one must identify the media attribute inside the style tag. The media attribute is utilized to identify the kind of device or medium for which the styles are designed. The media attribute encompasses an inventory of media types separated by a comma, where each media type embodies a definite classification of device or medium. A few illustrations of media types consist of "screen," "print," "handheld," and "tv."

Whilst denoting the media type, it is imperative to utilize the appropriate arrangement and orthography for every distinct media type. In conjunction, it is advisable to encompass solely those media types that are apposite to the styles being put into practice.

Allow us to elucidate this assertion by means of an illustration.


The following example embodies an HTML5 manuscript, which comprises a <head> part and a <body> part. Within the <head> section, two <style> elements are present, and each of them possesses a "media" attribute set to "screen" or "print", portraying the targeted media form for the application of styles. The first <style> element delineates the styles for the screen media kind, which encompass the background color, font family, and color of a body element, and also the styles for h4, p, and a elements. The second <style> element, however, formulates the styles for the print media type, which incorporates a distinct background color, font size, and color for the body element. Additionally, it also incorporates h4, p, and a element styles that are more appropriate for printed media. Furthermore, in the <body> part, an h4 element is followed by two <p> elements, with some sample text and a hyperlink, respectively. By employing the "media" attribute in the <style> elements, the document defines distinct styles for diverse media types, which can be advantageous for delivering an enhanced user experience across a plethora of devices and mediums.

<!DOCTYPE html>
      <title>How to define media type of style tag in HTML5?</title>
      <style media="screen">
         body {
            background-color: #f4f4f4;
            font-family: Arial, sans-serif;
            color: #333;
         h4 {
            color: #e67e22;
            font-size: 3em;
            text-align: center;
            margin-top: 50px;
         p {
            font-size: 1.2em;
            line-height: 1.5em;
            margin: 20px;
         a {
            color: #3498db;
            text-decoration: none;
            border-bottom: 1px solid #3498db;
            transition: border-bottom 0.3s ease-in-out;
         a:hover {
            border-bottom: 2px solid #3498db;
      <style media="print">
         body {
            background-color: #fff;
            color: #000;
         h4 {
            font-size: 2em;
         p {
            font-size: 1em;
            line-height: 1.2em;
            margin: 10px;
         a {
            color: #000;
            text-decoration: underline;
            border-bottom: none;
      <h4>How to define media type of style tag in HTML5?</h4>
      <p>This is some text. This is some more text. Some more text</p>
      <p><a href="#">Click here</a> to learn more</p>


To conclude, identifying the media class of a style tag in HTML5 can prove to be a daunting task, even for the most diligent of web developers. Nevertheless, by employing the obscure understanding of media query syntax and exercising shrewd application of infrequently utilized terms like "embosomed" and "inure," one can effectively encapsulate their stylesheet within a particular media class. Though this may appear to be a laborious undertaking, the advantages of a well-defined media class are plentiful, ranging from ensuring precise depiction across diverse devices to enhancing accessibility for individuals with distinct requirements. Thus, it is crucial for web developers to familiarize themselves with the complexities of media class definition in HTML5 and not evade the perplexing vocabulary that comes with it.

Updated on: 05-May-2023


Kickstart Your Career

Get certified by completing the course

Get Started