The CSS width, height, min-width, min-height, max-width, and max-height properties are used to set the size (including minimum/maximum) of an element.
- width – sets the width of the element
- height – sets the height of the element
- min-width – sets the smallest width the element can have
- min-height – sets the smallest height the element can have
- max-width – sets the largest width the element can have
- max-height – sets the largest height the element can have
Setting the Size
This is the size that the element will appear on all screens.
div {
width: 100%;
height: 80px;
}
img {
width: 100%;
height: auto;
}
Setting the Minimum and Maximum Size
This is the smallest and largest that an element is to appear on the screen. For instance, if someone is using a very large screen and you simply have the width set to 100%, the content of the element will stretch entirely across the screen, which could look awkward, and be difficult to read. So you set a max-width to something where it will grow with the screen size, but only to a certain point.
Similarly, you may want to set a minimum size for times when having the element smaller would look awkward or perhaps unreadable.
div {
max-width: 1440px;
min-width: 325px;
}
Width and Height Properties
We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.
Why 1SMARTchicken?
See More →
Thanks for your support!
CSS Books
All are affiliate links. Thank you for your support!
CSS NOTES:
- The “inherit”, “initial” and “unset” keywords can be used with any CSS property to set its value
- In CSS there are many ways to express a color value in a property
Feedback
If you see an error on the page or the code itself is incorrect or incomplete, or just plain wrong, please let us know. We’re always learning. NOTE: we do not sell your information and will not send you spam emails.