<style>
<style>
Tag
The <style>
tag in HTML is used to include internal CSS within a webpage. It allows adding CSS rules directly inside the HTML document to style its elements.
Syntax
<style>
/* CSS rules go here */
</style>
<style>
Demo
- Using the
<style>
element to add basic CSS styling to an HTML document:
This is a paragraph.
<!DOCTYPE html>
<html>
<head>
<style>
h1 {color: red;}
p {color: blue;}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Definition and Usage
- The
<style>
tag is used to define CSS styles for a document. - It specifies how HTML elements should be displayed in the browser.
- The
<style>
element should be placed inside the<head>
section of the document.
HTML
document. If the same property is defined in multiple stylesheets, the value from the last one read will be used.Attributes
Attribute | Value | Description |
---|---|---|
media | media_query | Indicates the media or device for which the media resource is intended or optimized. |
type | text/css | Defines the media type for the <style> tag. |
Default CSS Settings
Most browsers will display the <style>
element with the following default values:
style {
display: none;
}
Conclusion
The <style>
tag in HTML allows the inclusion of internal CSS to style a webpage directly within the HTML document. Placed inside the <head>
section, it defines how HTML elements should be displayed in the browser. This method of styling is useful for smaller projects or when external stylesheets aren't necessary. It helps control the visual presentation of the page, enhancing the user experience.
<slot>
The HTML <slot> element serves as a placeholder in web components, enabling external content to be inserted into a custom element, which enhances the reusability and flexibility of component design.
<template>
The <template> element in HTML enables the creation of reusable HTML snippets that are inactive and not displayed until triggered by JavaScript. This feature facilitates modular and dynamic content generation within web pages.