- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to apply CSS to iframe?
Define an inline frame with HTML tag <iframe>. The <iframe> tag is not somehow related to <frameset> tag, instead, it can appear anywhere in your document. The <iframe> tag defines a rectangular region within the document in which the browser can display a separate document, including scrollbars and borders. The src attribute is used to specify the URL of the document that occupies the inline frame.
We can easily apply CSS to an iframe, but let us first look at the attributes of the <iframe> −
src − This attribute is used to give the file name that should be loaded in the frame. Its value can be any URL.
name − This attribute allows you to give a name to a frame. It is used to indicate which frame a document should be loaded into.
marginheight − This attribute allows you to specify the height of the space between the top and bottom of the frame's borders and its contents. The value is given in pixels.
height − This attribute specifies the height of <iframe>.
scrolling − This attribute controls the appearance of the scrollbars that appear on the frame. This takes values either "yes", "no" or "auto".
longdesc − This attribute allows you to provide a link to another page containing a long description of the contents of the frame.
width − This attribute specifies the width of <iframe>.
Let us now apply CSS to iframe.
Applying Inline CSS to iframe
The style attribute is used to set inline css. We gave set the border, width and height −
<iframe style="border: 2px solid gray; width: 500px; height: 400px;" src="https://www.tutorialspoint.com/market/index.asp" id="Ebooks">
Example
Let us see the example −
<!DOCTYPE html> <html> <head> </head> <body> <h1>Courses</h1> <iframe style="border: 2px solid gray; width: 500px; height: 400px;" src="https://www.tutorialspoint.com/market/index.asp" id="Ebooks"> </iframe> </body> </html>
Applying Internal CSS to iframe
The style tag is used to set internal css to iframe. We have set the iFrame style to a new border, width and height −
iframe { border: 3px solid green; width: 500px; height: 400px; }
Example
Let us see an example −
<!DOCTYPE html> <html> <head> <style> iframe { border: 3px solid green; width: 500px; height: 400px; } </style> </head> <body> <h1>Courses</h1> <iframe src="https://www.tutorialspoint.com/market/index.asp" id="Ebooks"> </iframe> </body> </html>
- Related Articles
- How to apply CSS properties using jQuery?
- How to apply multiple CSS properties using jQuery?
- How to create and apply CSS to JavaScript Alert box?
- How to apply a 2D or 3D transformation to an element with CSS
- How to Apply Makeup?
- Alternatives to HTML5 iframe srcdoc?
- How to Apply to Foreign Universities
- How to apply bind() function in JavaScript?
- How to apply if tag in JSP?
- How to apply choose tag in JSP?
- How to apply forEach tag in JSP?
- How to apply forTokens tag in JSP?
- Is their any alternative to HTML5 iframe srcdoc?
- How to call a parent window function from an iframe using JavaScript?
- Apply style to the parent if it has a child with CSS and HTML
