Table of Contents[Hide][Show]
How to Create a 3D Button in HTML & CSS?
Well, crafting an HTML button using Cascading Stylesheets (CSS) might seem straightforward, yet it can pose challenges, especially for newcomers to HTML and CSS.
Despite its apparent simplicity, creating a button using the HTML tag can become intricate as you delve into the details of styling. This tag, however, offers the advantage of generating a button with just a single line of code.
You can also use tag that defines hyperlinks. So the above code can also be written as:
Click Me!
The button tag defines a simple clickable button. Inside a button element, you just need to set an attribute i.e., type="button"
that will define an HTML button.
Let’s dive into the process of crafting a 3D button using minimal HTML and CSS code. With a single line of HTML and a handful of CSS lines, you’ll be able to achieve an impressive 3D button effect that enhances your web design.
Steps to Create a 3D Button in HTML and CSS
Step 1: The HTML
- Take an anchor tag i.e.,
a
which defines a hyperlink, which will link some page or content when the button is clicked. Here, “half” is an attribute that will link our button to some page or content. - Now, we will name our button e.g., “3D Button” before the closing of the anchor tag.
3D Button
Step 2: The Cascading Stylesheet (CSS)
Now, we need to apply CSS to the HTML code that we wrote. Below is a CSS code for the hyperlink (button):
a { position: relative; color: #fff; text-decoration: none; background-color: #0094ff; font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; font-weight: bold; font-size: 40px; display: block; padding: 4px; border-radius: 10px; -webkit-border-radius: 10px; -moz-border-radius: 10px; box-shadow: 0px 10px 0px #1672b5, 0px 10px 30px #1672b5; -webkit-box-shadow: 0px 10px 0px #1672b5, 0px 10px 30px #1672b5; -moz-box-shadow: 0px 10px 0px #1672b5, 0px 10px 30px #1672b5; margin: 100px auto; text-align: center; transition: all .2s ease; -webkit-transition: all .2s ease; -moz-transition: all .2s ease; -ms-transition: all .2s ease; -o-transition: all .2s ease; }
Once, the style is applied to the HTML hyperlink or button, we need to apply :active
CSS pseudo-class to the hyperlink (button). Have a look at the :active
state code below:
a:active { position: relative; top: 6px; -webkit-box-shadow: 0px 3px 0px #095e9c, 0px 9px 25px #095e9c; -moz-box-shadow: 0px 3px 0px #095e9c, 0px 9px 25px #095e9c; box-shadow: 0px 3px 0px #095e9c, 0px 9px 25px #095e9c; }
Here is the complete source code of the button. You can modify the look and feel as per your requirement. Just copy and paste the below code and save it as an HTML file.
3D Buttons 3D Button
Button Demo
See the Pen 3D Button by Rajesh Rai (@WebsiteVidya) on CodePen.
You may also like these resources on Designing:
- 15 Best Text Editors For Web Designers
- 50 Sites With Royalty Free Stock Images For Commercial Use
- How To Get Royalty-Free Stock Photos With Google
- 500+ Photoshop Shortcuts To Speed Up Your Workflow
Wrap Up
In conclusion, mastering the art of crafting a 3D button in HTML and CSS opens the door to enhancing your web design with visually appealing elements. Through a clever combination of minimal HTML and carefully curated CSS properties, the process becomes accessible even to those new to web development.
The tutorial on how to create a 3D button in HTML and CSS has equipped you with the knowledge to seamlessly integrate this captivating element into your projects.
As you experiment and fine-tune the parameters, you’ll uncover the transformative potential of these few lines of code, adding depth and interactivity to your web interfaces with a touch of sophistication.