create-battery-using-css3

Creating battery with ::after css pseudo element is easy as it looks. We don’t need to use image for this purpose.
We are going to use ::after is a pseudo element which allows you to insert content after the selected element (without it needing to be in the HTML).

Horizontal Battery


<div class="battery"></div>
<style>
.battery {
margin: 0px auto;
  background-color: #fff;
  border: 5px solid #000;
  height: 70px;
  position: relative;
  width: 180px;
}
 .battery::after {
  background-color: #000;
  content: "";
  display: block;
  height: 20px;
  position: absolute;
  right: -12px;
  top: 20px;
  width: 10px;
} 
</style>

Demo:


Vertical Battery

<div class="battery_v"></div>
<style>
.battery_v {
  background-color: #fff;
  border: 5px solid #000;
  height: 150px;
  margin: 0 auto;
  position: relative;
  width: 70px;
}
.battery_v::after {
  background-color: #000;
  content: "";
  display: block;
  height: 10px;
  position: absolute;
  right: 20px;
  top: -15px;
  width: 15px;
}
</style>

Demo:


Look at the interactive battery status demo built using WebAPI and CSS3 here

References

https://developer.mozilla.org/en-US/docs/Web/CSS/::after