×

HTML <style> tag

The section of information that we want to style is contained in html style tag.

It includes CSS, which is used to design the text and images in the web page.

Syntax:

<head>
<title>…………. </title>
<style>
…………….
</style>
</head>

HTML:

<!DOCTYPE html>
<html>
<head>
<title> html style tag </title>
<style>
p {
color: #26b72b;
}
</style>
</head>
<body>
<p>This text will be green. Inline styles take precedence over CSS included externally.</p>
<p style="color: blue">The <code>style</code> attribute can override it, though.</p>
</body>
</html>

CSS:

p {
color: #f00;
}

Output:

HTML Style Tag

The <head> section of a page must have the <style> tag. The general rule is that it is preferable to save your styles in outer style sheets and implement them using <link> tags.

Similar to <link> tags, <style> tags can have media properties that include media queries. This tag allows the users to deploy internal style sheets on a web page only when they are based on media characteristics like viewport and width.

We use <style > element in the head of the document but using style tag in the external stylesheet is more appropriate. Use link tag to apply styles in the stylesheet.

Attributes

media

This characteristic tells us where to deploy the design. If the property is missing, a media query with all valuesare used as the field's value.

Nonce

In order to allow inline styles, a style-src content-security-policy uses a cryptographic nonce which is a one-time use integer. The server must produce a unique nonce value for each transmission of a policy.

type

If this property is specified, the only valid values are macthed for text/css or the empty string.

Examples

A simple stylesheet

The page in the example below is styled using a very basic style sheet:

<!doctype html>
<html>
<head>
<style>
p {
color: red;
}
</style>
</head>
<body>
<p> here we are gonna learn about html tag.</p>
</body>
</html>

Output:

HTML Style Tag

Multiple style elements

The following example shows the use of multiple style element:-

<!doctype html>
<html>
<head>
<style>
p {
color: white;
background-color: blue;
padding: 5px;
border: 1px solid black;
}
</style>
<style>
p {
color: blue;
background-color: yellow;
}
</style>
</head>
<body>
<p> here we are learning about the html style tag.</p>
</body>
</html>

Output:

HTML Style Tag

Including a media query

In this example, we are initially including a media attribute on the second <style> element:

<!doctype html>
<html>
<head>
<style>
p {
color: white;
background-color: blue;
padding: 5px;
border: 1px solid black;
}
</style>
<style media="all and (max-width: 500px)">
p {
color: blue;
background-color: yellow;
}
</style>
</head>
<body>
<p>in this example we are going to tell you about few more examples.</p>
</body>
</html>

Browser support:

List of browsers that support html style tag are given here:

Chrome: Yes, version 1 needed.

Microsoft Edge: Yes, version 12 needed.

Firefox: Yes, version 1 needed.

Safari: Yes, version 1 needed.

Opera: Yes, version 3.5 needed.


Related Topics

HTML <strong> tag

The strong element in HTML is used to display the real significant information in bold so that the user or reader will understand it easily. Syntax: <p> <strong>………… </strong> </p> Example Here, we will demonstrate how to...

2 minutes read.

What does HTML stand for?

HTML stands for Hyper Text Markup Language. We use this markup language to design a web page. Web browsers use this language to showcase text, videos, images, audio and other...

6 minutes read.

HTML Font Size

The HTML <font> tag uses the size attribute to specify the size of the text. We can set the size attribute’s value from 1 to 7. The default size of...

4 minutes read.

HTML City tag

HTML <City> tag HTML < cite > tag specifies a citation, a reference or title to a creative work, quoted content, books, websites, a research paper, a blog post, a painting,...

3 minutes read.

HTML &lt;body> alink Attribute

HTML <body> alink Attribute What is HTML? The HTML or HyperText Markup Language is used to design web pages. The file extension name for HTML file is ".html". It was released in...

2 minutes read.

HTML Text Format

Introduction HTML may format text in two different ways. The HTML tags define a text property to make it appear one way or another. A text element may also be formatted...

7 minutes read.

HTML Font Color

The HTML <font> tag has an attribute called color, which defines the color of the text. We use the color attribute inside the <font> tag to specify the color of...

6 minutes read.

CSS Clearfix

CSS Clearfix: A clearfix (or clear float) in CSS is for a component to clear or fix the child component, so we don’t need to insert additional markup. The clear...

4 minutes read.

HTML Layouts

HTML Layouts HTML templates provide a way for well-managed, well-structured responsive web pages to be organized. We could say that the HTML layout specifies how web pages can be set up....

4 minutes read.

How to append HTML code to a div using JavaScript?

In HTML, we have a div tag which is used to create a box where we can put a lot of other tags. So it works like a container. So,...

4 minutes read.

HTML <section> tag

The section element in HTML is used to define sections in a document. Syntax of Section Tag: <body> <h1>……….</h1> <section> <h2>……….</h2> <p> …………………………</p> </section> <section> <h2>………..</h2> <p>…………………………. <p> </section> </body> Examples of Section Tag Example 1: In this example, we use the HTML "section" element...

3 minutes read.

HTML Charsets

In this tutorial, we are going to discuss about the charsets in the HTML. The letters, numbers, and several other symbols are shown correctly by the web browser. All of this...

2 minutes read.

HTML <script> Tag

For embedding a client -side script, we use script tag in html tag. This <script> tag can be used for containing scripting statements. It can also point another external script file...

2 minutes read.

HTML Headings

The titles and subtitles of our webpages are known as HTML headings. Let’s not talk about webpages but giving heading to almost everything like normal paragraphs, articles or let it...

2 minutes read.

HTML <select> tag

This tag helps in making the drop-down list on the web page. This is highly used in HTML forms for taking the input from user. You can use the id attribute...

3 minutes read.

HTML Anchor

HTML Anchor The HTML anchor tags define a hyperlink that links to other pages on one page. It can create hyperlinks to any web page and files, locations or any other...

3 minutes read.

HTML5 Formatting

HTML Formatting HTML Formatting is a method of text formatting for a better appearance and look. HTML allows us to format text without using the CSS. HTML includes a lot of formatting tags....

6 minutes read.

HTML Paragraphs

In html, there are some elements which starts with new line and one of them is paragraph. Which is said to be a block of text. In html <p> tag...

4 minutes read.

HTML <br> tag

HTML is referred to as Hyper Text Markup Language, which is the most popular language for creating Web pages. HTML explains the construction of a Web page. It contains a...

4 minutes read.

HTML <svg> tag

SVG is used to determine the vector-based graphics in XML format. What is SVG? We utilize SVG tag to specify visuals for the website. The attribute of SVG in a HTML document...

2 minutes read.