
- CSS - Home
- CSS - Roadmap
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Types
- CSS - Measurement Units
- CSS - Selectors
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Border Block
- CSS - Border Inline
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursor
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS - Inline Block
- CSS - Dropdowns
- CSS - Visibility
- CSS - Overflow
- CSS - Clearfix
- CSS - Float
- CSS - Arrows
- CSS - Resize
- CSS - Quotes
- CSS - Order
- CSS - Position
- CSS - Hyphens
- CSS - Hover
- CSS - Display
- CSS - Focus
- CSS - Zoom
- CSS - Translate
- CSS - Height
- CSS - Hyphenate Character
- CSS - Width
- CSS - Opacity
- CSS - Z-Index
- CSS - Bottom
- CSS - Navbar
- CSS - Overlay
- CSS - Forms
- CSS - Align
- CSS - Icons
- CSS - Image Gallery
- CSS - Comments
- CSS - Loaders
- CSS - Attr Selectors
- CSS - Combinators
- CSS - Root
- CSS - Box Model
- CSS - Counters
- CSS - Clip
- CSS - Writing Mode
- CSS - Unicode-bidi
- CSS - min-content
- CSS - All
- CSS - Inset
- CSS - Isolation
- CSS - Overscroll
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - Pointer Events
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - Max Block Size
- CSS - Min Block Size
- CSS - Mix Blend Mode
- CSS - Max Inline Size
- CSS - Min Inline Size
- CSS - Offset
- CSS - Accent Color
- CSS - User Select
- CSS - Cascading
- CSS - Universal Selectors
- CSS - ID Selectors
- CSS - Group Selectors
- CSS - Class Selectors
- CSS - Child Selectors
- CSS - Element Selectors
- CSS - Descendant Selectors
- CSS - General Sibling Selectors
- CSS - Adjacent Sibling Selectors
- CSS Advanced
- CSS - Grid
- CSS - Grid Layout
- CSS - Flexbox
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Paged Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS - Image Sprites
- CSS - Important
- CSS - Data Types
- CSS3 Advanced Features
- CSS - Rounded Corner
- CSS - Border Images
- CSS - Multi Background
- CSS - Color
- CSS - Gradients
- CSS - Box Shadow
- CSS - Box Decoration Break
- CSS - Caret Color
- CSS - Text Shadow
- CSS - Text
- CSS - 2d transform
- CSS - 3d transform
- CSS - Transition
- CSS - Animation
- CSS - Multi columns
- CSS - Box Sizing
- CSS - Tooltips
- CSS - Buttons
- CSS - Pagination
- CSS - Variables
- CSS - Media Queries
- CSS - Functions
- CSS - Math Functions
- CSS - Masking
- CSS - Shapes
- CSS - Style Images
- CSS - Specificity
- CSS - Custom Properties
- CSS Responsive
- CSS RWD - Introduction
- CSS RWD - Viewport
- CSS RWD - Grid View
- CSS RWD - Media Queries
- CSS RWD - Images
- CSS RWD - Videos
- CSS RWD - Frameworks
- CSS References
- CSS Interview Questions
- CSS Online Quiz
- CSS Online Test
- CSS Mock Test
- CSS - Quick Guide
- CSS - Cheatsheet
- CSS - Properties References
- CSS - Functions References
- CSS - Color References
- CSS - Web Browser References
- CSS - Web Safe Fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
CSS Function - max()
The CSS max() function allows you to specify the largest (most positive) value from a list of comma-separated expressions as the CSS property value.
It is applicable to the values <length>, <frequency>, <angle>, <time>, <percent>, <number> or <integer>.
The max() function accepts one or more comma-separated expressions as parameters. The largest (most positive) expression value among these is used as the property value.
These expressions may contain arithmetic operations, literal values, or other valid arguments such as attr().
They can also contain nested max(), min() and max() functions. You have the option to use different units for each value and to use parentheses to control the order of calculations if needed.
Points to remember:
Mathematical expressions that use percentages for widths and heights in table columns, column groups, rows, row groups, and cells can be treated as if auto had been specified in both auto and fixed layout tables.
Nesting min() and other max() functions as expression values is allowed. These expressions are comprehensive mathematical expressions which allow direct addition, subtraction, multiplication and division without requiring the use of the calc() function itself.
-
The expression may consist of values containing addition (+), subtraction (-), multiplication (*), and division (/) operators, following the standard rules for operator precedence.
It's important to include a space on each side of the + and - operands. The operands in the expression can be any values that conform to the syntax.
Combining min() and max() values or including max() in a clamp() or calc() function is possible and often necessary.
Syntax
max( <calc-sum># )
The hash (#) mark multiplier indicates that the entity may be repeated one or more times (for example, the plus multiplier), but each occurrence is separated by a comma (',').
CSS max() - font-size
The function max() can be utilized to enable font size growth while ensuring it remains above a specified minimum, facilitating responsive font sizes while maintaining readability.
The following example demonstrates the usage of max(). Resize the browser window to see the effect.
<html> <head> <style> .text { font-size: max(16px, 5vw); background-color: lightgray; padding: 20px; margin: 20px; } p { font-size: max(1em, 5vw); background-color: yellow; padding: 20px; margin: 20px; } </style> </head> <body> <div class="text"> This text has a minimum font size of 16px or 5% of the viewport width, whichever is larger. </div> <p>This is a sample text with a minimum font size of 1em or 5vw, whichever is larger.</p> </body> </html>