Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between using the * universal selector and html?

Tags:

html

css

Know this might be a ridiculous question but what is the difference between using the * universal selector, which I know applies to every single element on the page and using just html?

For example:

* {
margin: 0;
padding: 0;
}

and

html {
margin: 0;
padding: 0;
}
like image 357
Jason Hyungchul Kang Avatar asked May 31 '16 15:05

Jason Hyungchul Kang


People also ask

What is the difference between type selector and universal selector?

Type selectors are the most basic kind of selector. They match to HTML elements by using the element name but without the angled brackets. For example, to apply a style to the h1 tags, h1 is the selector. The universal selector selects every single element in the whole document.

What is the difference between * and body selector in CSS?

body is an element selector (selects an element body ) while * is a universal selector (selects all elements).

What is universal selector in HTML?

The universal selector is a special type selector and can therefore be namespaced when using @namespace . This is useful when dealing with documents containing multiple namespaces such as HTML with inline SVG or MathML, or XML that mixes multiple vocabularies. ns|* - matches all elements in namespace ns.

What does the universal selector (*) Select?

The asterisk (*) is known as the CSS universal selectors. It can be used to select any and all types of elements in an HTML page. The asterisk can also be followed by a selector while using to select a child object. This selector is useful when we want to select all the elements on the page.


1 Answers

* wildcard is for all elements in page, doesn't matter what tag, classname, id or attribute it have.

html is only for <html> element.

Examples:

* {
  color:red;
}

div {
  color: green;
}
<p>this is red</p>
<p>this is red</p>
<div>this is red but styling specifically to green</div>
<p>this is red</p>
like image 167
Marcos Pérez Gude Avatar answered Sep 23 '22 10:09

Marcos Pérez Gude