×

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 Images

HTML has <img> tag to display image on the web pages or web application. This tag is an empty tag i.e. we don't have to close this tag while using. SYNTAX: <img src="source address" attributes="alt, height, width"> Example: <html>   <body>   <center>Image tag Example</center>   <img src="https://www.tutorialandexample.com/resources/images/favicon.png"    alt="tutorialandexample"/>   </body>   </html> Output: Image...

1 minute read.

HTML <address> Tag

Hyper Text Markup Language, HTML is the best markup language for creating Web pages. HTML consists of a wide variety of elements. In all of these elements, one element is...

4 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 Attribute

HTML Attribute HTML attributes are special words that provide additional information about the HTML element or attributes.The element or tags have attributes, which define the element's behavior.It also adds attributes with a start...

3 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 Search Box

The HTML search box is also known as the search bar. It is an input text field that is used to search the content. If the users want to explore...

7 minutes read.

HTML <span> tag

The span tag in HTML is used as an inline container element to mark up a specific or special chunk of a text or a section of a page. If you...

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

HTML Attributes

HTML Attributes provide the additional information about HTML elements. Attributes are always specified in the start tag. Attributes usually comes in pairs. lang Attribute This attribute helps in declaring the language...

2 minutes read.

Html Wbr Tag

The Line Break Opportunity element A word break opportunity is a place in text from where the browser breaks a line. This opportunity is represented by the element wbr in the...

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 Button Disabled

The HTML <button> element has many attributes, one of them is the disabled attribute. The button on which you apply the disabled attribute will not work, or we can say...

4 minutes read.

HTML Id Attribute

The HTML id attribute represents the unique identifier for an element of the HTML document. Each element has its unique identifier. The id attribute is a global attribute that can be...

12 minutes read.

HTML5 Tags

HTML5 Tags A list of newly included tags is provided in HTML5. These HTML 5 tags (elements) provide a better structure for the document. This list shows description of all HTML...

3 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 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 <source> tag

For media attributes, such as <video> tag, <audio> tag, and <picture> tag, we use the <source> tag in html for adding such type of multiple media html elements in our...

4 minutes read.

HTML Lists

HTML List HTML lists are used to specify data sets. All lists can include one or more elements from the list. HTML lists are available in three different types: Ordered List or...

4 minutes read.

HTML &lt;blink> Tag

In HTML, the blink tag is used to create the text which flashes. The blink tag is an inline element in HTML. It is observed that the blink tag used...

2 minutes read.

How to add Google Translate Button on your Webpage?

Google translator is a multi-language translator used for translating the webpage. Google develops it. In today's digital age, it is essential because information is available worldwide in some specific language...

5 minutes read.