×

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 <sub> tag

The sub element in HTML is used to describe one or more subscript texts. If The sub tag shows the text which is presented in a smaller font and below...

2 minutes read.

Difference between HTML and DHTML

Introduction to HTML HTML stands for Hypertext Markup Language. It is a standard web language used to create web pages and applications. HTML is used to define the structure and content...

4 minutes read.

HTML Youtube

<object> element: It embed the object within the HTML documents and embed plug-ins such as Java applets, PDF readers, Flash Players etc in web pages. Example: <object width="100" height="100" data="bookmark.swf"></object> <embed> element: It defines an embedded...

1 minute read.

How to Create a Portfolio Gallery using HTML and CSS?

First, before starting this, the user should know some of the basics of HTML and CSS to create a portfolio gallery. To add more functionality to the website, we can also...

7 minutes read.

How to change font in HTML

To give style to the content of your website, you may change the font of the text and make your website look attractive to the user. There are several methods which...

4 minutes read.

HTML Data Tag

HTML Data Tag: The HTML < data > tag is used to transmit its content to a machine-readable version. The data are presented in a particular format. It is useful...

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

The Samp tag in HTML is used for defining the sample output from the computer program. This tag is a phrase type tag and a container tag that means the...

2 minutes read.

HTML Tutorial

Introduction This HTML tutorial helps beginners and professionals to learn HTML easily. HTML is a widely used web technology for website development. It stands for Hyper Text Markup Language. It is mainly used to...

7 minutes read.

Html <colgroup> Tag

A HTML table's column group is specified by the "colgroup" tag. If you want to apply various properties to one or more <col> elements in an HTML table, then you...

4 minutes read.

HTML Forms

Forms are required when we want to collect data from the user. Html forms consists of different fields to take user inputs such as: input, text area, checkbox, password, radio...

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

Caption Tag in HTML

Caption Tag in HTML: The < caption > tag in HTML describes the heading of a table in the HTML text. Browsers typically make the text found above the table...

4 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 Form Input Types

HTML Form Input Types An important element of the HTML form is < input type= "> in HTML. The type attribute of the input element can be of different types, which...

8 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 &lt;datalist >Tag

The autocomplete feature in HTML files is provided by the <datalist> tag. It can be used in conjunction with an input tag to enable users to quickly fill out form...

4 minutes read.