HTML Element Style How to - Center an iframe








Question

We would like to know how to center an iframe.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
iframe {<!--from  www  . j ava  2 s .c o  m-->
  width: 100px;
  height: 100px; /* used for demonstration */
  margin: 0 auto;
  display: block;
  background-color: #000; /* used for demonstration */
}
</style>
</head>
<body>
  <iframe></iframe>
</body>
</html>

The code above is rendered as follows: