The HTML <style> Element

Share

The image is taken from unsplash.com.

Definition and usage

The HTML <style> element is used to style an HTML document or part of a document without the need for an external stylesheet.

It is usually placed in the <head> element of an HTML document, and it specifies how HTML elements should render in a browser.

Coding example:

    The <style> element being used to style the h2 tag

    Attributes

    Attributes provide additional properties of an HTML element and are always defined in the opening tag.

    The <style> element contains attributes that define additional characteristics of the element, and it also supports the Global Attributes in HTML.

    Note: Click on the link below to read on Global Attributes in HTML.

    Attributes of the <style> element

    Attribute

    Value

    Description

    type

    text/css

    It species the styling

    language.

    media

    media_query

    It specifies the media the

    styles apply to.

    Single and multiple styles

    Single styling applies the <style> element once in a document while multiple styling applies the <style> element more than once in a document.

    Single and multiple styling

    Conclusion

    Although the <style> element provides a document’s CSS style information, the generally preferred method is to export an external stylesheet.