DEV Community

Cover image for HTML tags | style
Carlos Espada
Carlos Espada

Posted on • Edited on

3

HTML tags | style

It is used to assign styles to the document or to a part of it. Inside it will contain CSS that will define how HTML elements are rendered in a browser.

It must go inside <head>. It is generally better to put styles in external style sheets and link them using the <link> element.

Like the <link> element, the <style> element can include media attributes that contain media queries to allow you to selectively apply styles based on certain characteristics such as the width of the viewport.

It can have several attributes:

  • type: defines the style language as a MIME type (the charset must not be specified). This attribute is optional and its default value is text/css (it cannot have any other value than that or empty string). In modern web documents there is no reason to use it.
  • media: defines to which media the style should be applied. Its value is a media query whose default value is all.
  • nonce: a cryptographic nonce (number used once) used to whitelist inline styles in a style-src Content-Security-Policy. The server must generate a unique nonce value each time it broadcasts a policy. It is essential to provide a nonce that cannot be guessed, otherwise bypassing the policy of a resource is very easy.
  • title: specifies a name so that you can use alternate style sheets.

If multiple <style> and <link> elements are included to external style sheets in the same document, they will be applied to the HTML document in the order in which they have been included, so it is important to take this into account to avoid unwanted effects.

  • Type: none
  • Self-closing: No
  • Semantic value: No

Definition and example | Support

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more