Атрибут target (от англ. «target» — «цель, мишень») указывает место (фрейм или окно браузера) в которое должен быть загружен, указанный ресурс.
Для элемента определяет имя фрейма, в котором будут открываться все ссылки. Действие target в качестве атрибута элемента распространяется на все ссылки документа, кроме ссылок в которых это действие переопределяется собственными атрибутами target .
Для элемента определяет указывает место (фрейм или окно браузера) в которое должен быть загружен ответ сервера (результат отправки данных формы).
Синтаксис
Значения
_blank Загружает страницу в новую вкладку браузера. _self Загружает страницу в текущую вкладку. _parent Загружает страницу во фрейм-родитель; если фреймов нет, то это значение работает как _self . _top Отменяет все фреймы и загружает страницу в полном окне браузера; если фреймов нет, то это значение работает как _self .
Значение по умолчанию
Применяется к тегам
Отличия HTML 4.01 от HTML 5
В HTML 4.01 атрибут считался устаревшим и не рекомендован к использованию, в HTML 5 он полностью поддерживается.
An HTML iframe is used to display a web page within a web page.
HTML Iframe Syntax
The HTML tag specifies an inline frame.
An inline frame is used to embed another document within the current HTML document.
Syntax
Example
Or you can add the style attribute and use the CSS height and width properties:
Example
Iframe — Remove the Border
By default, an iframe has a border around it.
To remove the border, add the style attribute and use the CSS border property:
Example
With CSS, you can also change the size, style and color of the iframe’s border:
Example
Iframe — Target for a Link
An iframe can be used as the target frame for a link.
The target attribute of the link must refer to the name attribute of the iframe:
Example
Chapter Summary
The HTML tag specifies an inline frame
The src attribute defines the URL of the page to embed
Always include a title attribute (for screen readers)
The height and width attributes specify the size of the iframe
Use border:none; to remove the border around the iframe
HTML Exercises
HTML iframe Tag
For a complete list of all available HTML tags, visit our HTML Tag Reference.
COLOR PICKER
Report Error
If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:
Thank You For Helping Us!
Your message has been sent to W3Schools.
Top Tutorials
Top References
Top Examples
Get Certified
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.
Jennifer Kyrnin is a professional web developer who assists others in learning web design, HTML, CSS, and XML.
The iframe tag is used to display a web page inside a web page. When you create a document to be inside an iframe, any links in that frame will automatically open in that same frame. But with the attribute on the link (the element or elements), you can specify where the links will open.
The first step is to give your iframe a unique name with the name attribute. Then, it’s a matter of pointing your links at that frame using the ID as the value of the target attribute:
If you add a target to an ID that doesn’t exist in the current browser session, the link will open in a new browser window, with that name. After the first time, any links that point to that named target will open in the same new window.
If you don’t want to name every window or every frame with an ID, you can still target some specific windows without needing a named window or frame. These are called the standard targets.
The Four Target Keywords
There are four target keywords that don’t require a named frame. These keywords allow you to open links in specific areas of the web browser window that might not have an ID associated with them. These are the targets that web browsers recognize:
This is the default target for any anchor tag. If you don’t set the target attribute or you use this target, the link will open in the same window or frame that the link is in.
Iframes are embedded inside web pages. You can embed an iframe in a page that is inside another iframe on another web page. When you set the target attribute to _parent, the link will open in the web page that is holding the iframe.
In most situations with iframes, this target will open links in the same way that the _parent target does. But if there is an iframe inside an iframe, the _top target opens links in the highest-level window in the series, removing all the iframes.
The most commonly used target, this opens the link in an entirely new window, similar to a popup.
How to Name Your Frames
When you build a web page with iframes, it’s a good idea to give each one a specific name. This helps you remember what they are for and allows you to send links to those specific frames. For example:
Setting a Default Target
You can also set a default target on your web pages using the element. Set the target attribute to the name of the iframe you want all links to open in. You can also set default targets for one of the four target keywords.
iFrame is a very convenient way to display an external content on your webpage. However, it’s little bit complicate if you want to add additional or alter the existing CSS style. You cannot simply add CSS on the parent/wrapper page. In this tutorial, we’ll show you how to use JavaScript to inject CSS into iFrame.
In the snippet below, once everything was loaded, we’ll get the iFrame element by ID. Then get the contentDocument and inject our styles into iFrame using innerHTML.
window.onload = function() < let myiFrame = document.getElementById("myiFrame"); let doc = myiFrame.contentDocument; doc.body.innerHTML = doc.body.innerHTML + ''; >
Or you can do it with jQuery.
$("#myiFrame").on("load", function() < let head = $("#myiFrame").contents().find("head"); let css = ''; $(head).append(css); >);
Example
For example, here is the 3D CSS Progressbar tutorial page that we want to add to ours using iframe.
Suppose that we want to change the length of the progress bar to 45%. Unfortunately, we can’t do something like this from our parent CSS.
Let’s try using JavaScript. It’s important that you’ll need to wait until the iFrame was loaded before you can inject the CSS. In this case, we’ll put the code in onload event listener.
window.onload = function() < let frameElement = document.getElementById("myiFrame"); let doc = frameElement.contentDocument; doc.body.innerHTML = doc.body.innerHTML + '.bar '; >
Adding CSS File to iFrame
You can add entire CSS file instead of injecting separated styles by creating link and add it to the iframe’s head.
This method does not work with cross domain content. You’ll need to set appropriate CORS header but it’s not recommended due to security risks.
TK Engineer, Web Developer, Ex-Mutual Funds Software Developer. He founded Red Stapler in 2015 to share useful resources for everyone interested in web design, web development and programming. Subscribe his YouTube Channel or Twitter for weekly tips and tutorials.