Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Change the font size of a button with CSS
To change the font size of a button with CSS, you can use different properties to control text appearance. The font size affects button readability and visual hierarchy on your webpage.
Syntax
button {
font-size: value;
}
Method 1: Using font-size Property
The CSS font-size property directly controls the text size inside buttons. This is the most straightforward approach −
Example
<!DOCTYPE html>
<html>
<head>
<style>
.normal-btn {
font-size: 16px;
padding: 8px 16px;
margin: 5px;
cursor: pointer;
}
.large-btn {
font-size: 24px;
padding: 8px 16px;
margin: 5px;
cursor: pointer;
}
.small-btn {
font-size: 12px;
padding: 8px 16px;
margin: 5px;
cursor: pointer;
}
</style>
</head>
<body>
<h3>Font Size Variation in Buttons</h3>
<button class="normal-btn">Normal (16px)</button>
<button class="large-btn">Large (24px)</button>
<button class="small-btn">Small (12px)</button>
</body>
</html>
Three buttons appear with different text sizes: a normal button with 16px text, a larger button with 24px text, and a smaller button with 12px text.
Method 2: Using transform Property
The CSS transform property with scale() function scales the entire button including text size −
Example
<!DOCTYPE html>
<html>
<head>
<style>
.base-btn {
font-size: 16px;
padding: 10px 20px;
margin: 10px;
cursor: pointer;
border: 1px solid #ccc;
background-color: #f0f0f0;
}
.scaled-large {
transform: scale(1.3);
}
.scaled-small {
transform: scale(0.8);
}
</style>
</head>
<body>
<h3>Button Scaling with Transform</h3>
<button class="base-btn">Normal</button>
<button class="base-btn scaled-large">Scaled Large</button>
<button class="base-btn scaled-small">Scaled Small</button>
</body>
</html>
Three buttons appear with different sizes: a normal button, a larger scaled button (1.3x), and a smaller scaled button (0.8x). The transform scales both text and button dimensions.
Comparison
| Property | Affects | Best For |
|---|---|---|
font-size |
Text only | Changing text size while keeping button dimensions |
transform: scale() |
Entire button | Proportionally resizing the whole button |
Conclusion
Use the font-size property when you need to change only the text size, and the transform: scale() property when you want to resize the entire button proportionally. Both methods provide effective ways to control button appearance.
Advertisements
