-
Notifications
You must be signed in to change notification settings - Fork 22.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CSS module: box sizing & box model #33182
Changes from 23 commits
426fd0e
51cbf03
bc85184
520756d
b37d5cf
eb45705
5abaf68
e8121fe
7319e8a
7df1599
427f8b2
b47235f
45a597a
9b06e08
805b2e0
1c227c1
bc68520
ad8d5e0
b9d810a
5f95017
b1e433b
9b835d2
64e63c1
eb57352
0bcf38c
7c80c53
4574f20
cd0bf46
10290b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -6,12 +6,64 @@ page-type: glossary-definition | |||||||||||||
|
||||||||||||||
{{GlossarySidebar}} | ||||||||||||||
|
||||||||||||||
In CSS, the _intrinsic size_ of an element is the size it would be based on its content, if no external factors were applied to it. For example, inline elements are sized intrinsically: `width`, `height`, and vertical margin and padding have no impact, though horizontal margin and padding do. | ||||||||||||||
In CSS, the _intrinsic size_ of an element is the size it would be based purely on its content without taking into account the effects of the context it appears in, for example, the sizing applied by CSS [box model](/en-US/docs/Learn/CSS/Building_blocks/The_box_model) properties. An element's intrinsic sizes are the element's {{cssxref("min-content")}} and {{cssxref("max-content")}} sizes. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JUST "FWIW", it took me a while to get my head around because I learned the concept in terms of images, where the inherent size max/min is the same. So reading this confused me a bit - because I was assuming that text and other elements might be the same. What really helped with my confusion was the examples, which make it clear that the value depends on the content, and can hence have a max and min. |
||||||||||||||
|
||||||||||||||
How intrinsic sizes are calculated is defined in the [CSS Intrinsic and Extrinsic Sizing Specification](https://www.w3.org/TR/css-sizing-3/#intrinsic-sizes). | ||||||||||||||
Inline elements are sized intrinsically: [sizing](/en-US/docs/Web/CSS/CSS_box_sizing) and [box](/en-US/docs/Web/CSS/CSS_box_model) properties including {{cssxref("height")}}, {{cssxref("width")}}, {{cssxref("block-size")}}, {{cssxref("inline-size")}}, and {{cssxref("padding-block")}} and {{cssxref("margin-block")}} have no impact on them ( though {{cssxref("margin-inline")}} and {{cssxref("padding-inline")}} do). | ||||||||||||||
|
||||||||||||||
Intrinsic sizing takes into account the `min-content` and `max-content` size of an element. For text the `min-content` size would be if the text wrapped as small as it can in the inline direction without causing an overflow, doing as much soft-wrapping as possible. For a box containing a string of text, the `min-content` size would be defined by the longest word. The keyword value of `min-content` for the {{cssxref("width")}} property will size an element according to the `min-content` size. | ||||||||||||||
#### min-content | ||||||||||||||
|
||||||||||||||
The `max-content` size is the opposite — in the case of text, this would have the text display as wide as possible, doing no soft-wrapping, even if an overflow was caused. The keyword value `max-content` exposes this behavior. | ||||||||||||||
For example, the minimum intrinsic, or {{cssxref("min-content")}} size of a {{htmlelement("span")}} element is the minimum size it would have if it was floated with no other CSS box properties applied inside a container with a inline-size of `0px`. For text, the `min-content` size would be if the text was wrapped as small as possible in the inline direction without causing an overflow, with as much soft-wrapping as possible. For a box containing a string of text, the `min-content` size would be defined by the longest word. The keyword value of `min-content` for the {{cssxref("width")}} and {{cssxref("inline-size")}} properties will size an element according to the `min-content` size. | ||||||||||||||
estelle marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Does this still say what you want it to say? Trying to simplify it a bit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed the order of the page so that the values are way lower down, as this is a glossary page I wanted to de-emphasize guide-ish stuff (css properties and values), so moved all the non-guide stuff above the first h4, and then showed examples of min and max intrinsic content, changing the headings to what I am defining rather than the properties used. I only used h4 because i could not get the "show this example to work without a header" syntax to work and spent way too long trying. |
||||||||||||||
|
||||||||||||||
For images the intrinsic size has the same meaning — it is the size that an image would be displayed if no CSS was applied to change the rendering. By default images are assumed to have a "1x" pixel density (1 device pixel = 1 CSS pixel) and so the intrinsic size is simply the pixel height and width. The intrinsic image size and resolution can be explicitly specified in the {{Glossary("EXIF")}} data. The intrinsic pixel density may also be set for images using the [`srcset`](/en-US/docs/Web/HTML/Element/img#srcset) attribute (note that if both mechanisms are used, the `srcset` value is applied "over" the EXIF value). | ||||||||||||||
```html hidden | ||||||||||||||
<div><p>Text wraps, making the element only as wide as its longest word.</p></div> | ||||||||||||||
estelle marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
```css hidden | ||||||||||||||
p { | ||||||||||||||
width: min-content; | ||||||||||||||
estelle marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
background-color: palegoldenrod; | ||||||||||||||
} | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
{{ EmbedLiveSample('min-content', '100%', '200') }} | ||||||||||||||
|
||||||||||||||
#### max-content | ||||||||||||||
|
||||||||||||||
The maximum intrinsic size, or {{cssxref("max-content")}} size is the opposite. It is the element's size if the container's inline size were infinite. Text content would display as wide as possible, with no soft-wrapping, even if it overflowed its container. The keyword value `max-content` sets this behavior. | ||||||||||||||
|
||||||||||||||
```html hidden | ||||||||||||||
<div><p>Element grows as text doesn't wrap.</p></div> | ||||||||||||||
<div> | ||||||||||||||
<p> | ||||||||||||||
This paragraph may be wider than the width of the entire page and yet it | ||||||||||||||
won't wrap because <code>width: max-content</code> is set. It therefore may | ||||||||||||||
overflow its container. | ||||||||||||||
</p> | ||||||||||||||
</div> | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
```css hidden | ||||||||||||||
p { | ||||||||||||||
width: max-content; | ||||||||||||||
background-color: palegoldenrod; | ||||||||||||||
} | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
{{ EmbedLiveSample('max-content', '100%', '200') }} | ||||||||||||||
|
||||||||||||||
Intrinsic sizes and how they are calculated are defined in the [CSS sizing module](/en-US/docs/Web/CSS/CSS_box_sizing). | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It feels a bit weird to have this nested away in a subsection. Make it a note nearer the top? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved way up |
||||||||||||||
|
||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add another subheading for the part about images? We are moving on to a different subject. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved the images part way higher, above any examples. |
||||||||||||||
Intrinsic size has the same meaning for images as for text — the size at which the images are displayed if no CSS is applied to change the rendering. | ||||||||||||||
|
||||||||||||||
Pixel density and resolution affect intrinsic size. By default, images are assumed to have a "1x" pixel density (1 device pixel = 1 CSS pixel), in which case the intrinsic size is simply the pixel height and width. An image's intrinsic size and resolution can be explicitly specified in its {{Glossary("EXIF")}} data. Image pixel density may also be set for images using the [`srcset`](/en-US/docs/Web/HTML/Element/img#srcset) attribute. Note that, if both mechanisms are used, the `srcset` value is applied "over" the EXIF value. | ||||||||||||||
|
||||||||||||||
## Extrinsic sizing | ||||||||||||||
|
||||||||||||||
The opposite of _intrinsic size_ is **_extrinsic size_**, which is based on the context of an element, without regard for its contents. Extrinsic sizing is determined by box model property values. With extrinsic sizing, percentages specify the size of a box with respect to the box's containing block. | ||||||||||||||
|
||||||||||||||
## See also | ||||||||||||||
|
||||||||||||||
- CSS {{cssxref("min-content")}}, {{cssxref("max-content")}}, and {{cssxref("fit-content")}} property values. | ||||||||||||||
- CSS {{cssxref("aspect-ratio")}} property | ||||||||||||||
- [CSS box sizing](/en-US/docs/Web/CSS/CSS_box_sizing) module | ||||||||||||||
- [CSS sizing specification: intrinsic sizes](https://www.w3.org/TR/css-sizing-3/#intrinsic-sizes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the last sentence confusing, because it reads as though CSS sets the intrinsic size, but intrinsic (at least in English) would mean "inherent" - so not something you can "apply". I'm pretty sure this fixes it.