💡 퀵 접속: htm.kr/iframe
<iframe> 태그는 웹 페이지 내에 다른 웹 페이지를 삽입하는 데 사용되는 HTML 요소입니다.
주로 외부 콘텐츠를 현재 페이지에 통합할 때 사용됩니다.
<iframe
src="https://example.com"
width="600"
height="400"
title="예제 페이지"
sandbox="allow-same-origin allow-scripts"
loading="lazy">
</iframe>
| 속성 | 설명 | 예시 |
|---|---|---|
| src | 삽입할 페이지의 URL | src="https://example.com" |
| width | iframe의 너비 | width="600" |
| height | iframe의 높이 | height="400" |
| title | 접근성을 위한 제목 | title="예제 페이지" |
| sandbox | 보안 제한 설정 | sandbox="allow-same-origin allow-scripts" |
| loading | 지연 로딩 설정 | loading="lazy" |
<iframe
src="https://example.com"
width="100%"
height="300"
title="기본 예제">
</iframe>
<iframe
width="560"
height="315"
src="https://www.youtube.com/embed/VIDEO_ID"
title="YouTube video player"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen>
</iframe>
<iframe
src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3165.297944506569!2d126.9779693!3d37.566295!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x0%3A0x0!2zMzfCsDMzJzU4LjYiTiAxMjbCsDU4JzQ2LjciRQ!5e0!3m2!1sko!2skr!4v1234567890"
width="600"
height="450"
style="border:0;"
allowfullscreen=""
loading="lazy"
title="Google Maps">
</iframe>
/* 반응형 iframe */
.responsive-iframe {
position: relative;
width: 100%;
padding-bottom: 56.25%; /* 16:9 비율 */
height: 0;
}
.responsive-iframe iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: none;
}
/* 테두리 및 여백 설정 */
.custom-iframe {
border: 2px solid #ddd;
border-radius: 8px;
margin: 20px 0;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}