How to apply internal CSS style to HTML elements using HTML tag name

What is HTML Tag Name?

In HTML, a tag name is the part of an HTML element that comes between the opening "<" and closing ">" brackets.

For example, in the HTML element <p>, the tag name is "p" and this represents a paragraph element. In the same way, in the HTML element <div>, the tag name is "div".

In CSS, HTML tag name can be used as selector to apply CSS style to the all specified elements.

Please note that when an HTML tag name is used in internal CSS style, the CSS style specified for that tag will be applied to all elements of the same kind throughout the document.

Let's take a look at the following example.:

Example of Using HTML Tag Name as CSS Selector

Add an HTML <style> element inside the <head> section of your HTML document.

Add p { color: red; font-size: 18px;} CSS style code inside the <style> element. Here "p" is used to select all paragraph elements in the current HTML document. CSS property 'color' has been set to 'red' and 'font-size' to '18px'.

Example of HTML Class Name


Output of the above example

Example of Using HTML Tag Name to Apply Internal CSS Style


CSS style element added in the head element. Color and font size of the following paragraph have been changed using HTML tag name as selector.

Para 1: CSS style has been applied to the parapgraph using HTML tag name.

Para 2: CSS style has been applied to the parapgraph using HTML tag name.

In the output, both 'Para 1' and 'Para 2' have the red color and same font size as you have used paragraph tag name 'p' as selector for CSS style. If you add more paragraph elements, they will have the same CSS style.

Live Code Playground

In the following HTML code editor, you can practice the above code by creating new HTML tag name selectors. Click on the 'Run Code' button to render the code; the rendered page will be displayed in the following HTML Code Output frame. Practice until you become comfortable and proficient with your code.

HTML logo HTML Online Editor
HTML Code Output