<percentage>
Quick Summary for <percentage>
The <percentage> CSS data type represents a percentage value. It is often used to define a size as relative to an element's parent object. Numerous properties can use percentages, such as width, height, margin, padding, and font-size.
Code Usage for <percentage>
<div style="background-color:navy;">   <div style="width:50%; margin-left:20%; background-color:chartreuse;">     Width: 50%, Left margin: 20%   </div>   <div style="width:30%; margin-left:60%; background-color:pink;">     Width: 30%, Left margin: 60%   </div> </div> 
More Details for <percentage>

<percentage>

The <percentage> CSS data type represents a percentage value. It is often used to define a size as relative to an element's parent object. Numerous properties can use percentages, such as width, height, margin, padding, and font-size.

Note: Only calculated values can be inherited. Thus, even if a percentage value is used on the parent property, a real value (such as a width in pixels for a <length> value) will be accessible on the inherited property, not the percentage value.

Syntax

The <percentage> data type consists of a <number> followed by the percentage sign (%). Optionally, it may be preceded by a single + or - sign, although negative values are not valid for all properties. As with all CSS dimensions, there is no space between the symbol and the number.

Interpolation

When animated, values of the <percentage> data type are interpolated as real, floating-point numbers. The speed of the interpolation is determined by the timing function associated with the animation.

Examples

Width and margin-left

<div style="background-color:navy;">   <div style="width:50%; margin-left:20%; background-color:chartreuse;">     Width: 50%, Left margin: 20%   </div>   <div style="width:30%; margin-left:60%; background-color:pink;">     Width: 30%, Left margin: 60%   </div> </div> 

The above HTML will output:

Font-size

<div style="font-size:18px;">   <p>Full-size text (18px)</p>   <p><span style="font-size:50%;">50% (9px)</span></p>   <p><span style="font-size:200%;">200% (36px)</span></p> </div> 

The above HTML will output:

Specifications

Specification
CSS Values and Units Module Level 5 # percentages

See also

<length-percentage> CSS Values and Units

Last modified: Nov 21, 2021, by MDN contributors

Select your preferred language English (US)DeutschEspañolFrançais日本語한국어Русский中文 (简体) Change language

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Categories in CSS
css
Search CSS
Search CSS by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

You could also follow me on twitter. I have a couple of youtube channels if you want to see some video related content. RuneScape 3, Minecraft and also a coding channel here Web Dev.

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote
In this case my anchor this week becomes driving almost 2hrs outside of Atlanta to one of my favorite hard core gyms in the world.. MetroFlex aka The Dungeon. The gym owners turn the heat way up so it becomes a fun sweat box and the gym members just watch from afar and leave me alone. I happily drive myself long distances to find MY ANCHOR. Our anchor allows us to have balance, focus and be as productive as possible. And if you're in the middle of a heavy set and your headphones start to fall off your head, like mine did here.. well.. f*ck the headphones. Let em break and fall. You can always get a new pair, but the iron ain't ever gonna lift itself.
Unknown
Random CSS Property

repeat()

The repeat() CSS function represents a repeated fragment of the track list, allowing a large number of columns or rows that exhibit a recurring pattern to be written in a more compact form.
repeat() css reference