CSS Link Buttons
CSS can be used to make HTML links look like buttons.
Combine several CSS properties, such as background-color, padding, text-decoration, and display, to show links as boxes or buttons.
Filled button
A link styled as a solid red button that darkens on hover.
Prompt
An HTML page that styles a link as a filled button.
In an internal
<style> block, give a:link and a:visited a red (#f44336) background, white text, 14px 25px padding, centered text, no underline, and inline-block display. On a:hover and a:active, change the background to red. Add a link in the body.
Output: complete HTML page
index.html
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
a:link, a:visited {
background-color: #f44336;
color: white;
padding: 14px 25px;
text-align: center;
text-decoration: none;
display: inline-block;
}
a:hover, a:active {
background-color: red;
}
</style>
</head>
<body>
<a href="https://prompt-cookbook.com">This is a link</a>
</body>
</html>
Bordered button
A link styled as a bordered button that fills with green on hover.
Prompt
An HTML page that styles a link as a bordered button that fills on hover.
In an internal
<style> block, give a:link and a:visited a white background, black text, a 2px solid green border, 10px 20px padding, centered text, no underline, and inline-block display. On a:hover and a:active, set a green background and white text. Add a link in the body.
Output: complete HTML page
index.html
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
a:link, a:visited {
background-color: white;
color: black;
border: 2px solid green;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
}
a:hover, a:active {
background-color: green;
color: white;
}
</style>
</head>
<body>
<a href="https://prompt-cookbook.com">This is a link</a>
</body>
</html>