SVG
스케일러블 벡터 그래픽스(Scalable Vector Graphics, SVG)는 2차원 벡터 그래픽을 표현하기 위한 XML 기반의 파일 형식으로, 1999년 W3C(World Wide Web Consortium)의 주도하에 개발된 오픈 표준의 벡터 그래픽 파일 형식이다. SVG 형식의 이미지와 그 작동은 XML 텍스트 파일들로 정의 되어 검색화·목록화·스크립트화가 가능하며 필요하다면 압축도 가능하다.
- 인터넷 익스플로러9 버전 이상부터 지원된다.
- XML을 이용하여 라인, 곡선, 기하학적인 그래픽 표현이 가능하다.
- 벡터 방식이기 때문에 확대하거나 축소가 가능하다.
- DOM 단위로 컨트롤이 가능하지만 문서 복잡도가 증가되면 렌더링이 느려진다.
rect(사각형)
속성
속성 | 설명 |
---|---|
x | 사각형의 X좌표 값을 설정합니다. |
y | 사각형의 Y좌표 값을 설정합니다. |
width | 사각형의 가로 값을 설정합니다. |
height | 사각형의 세로 값을 설정합니다 |
rx | 사각형의 보더 굴곡의 X값을 설정합니다. |
ry | 사각형의 보더 굴곡의 Y값을 설정합니다. |
<div class="svgBox">
<svg class="svg">
<rect fill="#f48fb1" width="100" height="100" x="30" y="30"/>
</svg>
<svg class="svg">
<rect fill="#f48fb1" width="100" height="100" x="30" y="30" stroke="#880e4f" stroke-width="5"/>
</svg>
<svg class="svg">
<rect fill="#f48fb1" width="100" height="100" x="30" y="30" rx="20" ry="20"/>
</svg>
<svg class="svg">
<rect fill="#f48fb1" width="100" height="100" x="30" y="30" stroke="#880e4f" stroke-width="5" rx="20" ry="20"/>
</svg>
</div>
circle(원형)
<div class="svgBox">
<svg class="svg">
<circle fill="#f48fb1" r="60"cx="80" cy="80"/>
</svg>
<svg class="svg">
<circle fill="#f48fb1" r="60"cx="80" cy="80" stroke="#880e4f" stroke-width="5"/>
</svg>
<svg class="svg">
<ellipse fill="#f48fb1" rx="60" ry="40"cx="80" cy="80"/>
</svg>
<svg class="svg">
<ellipse fill="#f48fb1" rx="60" ry="40" cx="80" cy="80" stroke="#880e4f" stroke-width="5"/>
</svg>
</div>
polygon(다각형)
<div class="svgBox">
<svg class="svg">
<polygon fill="#f48fb1" points="137,146 8,107 107,15"/>
</svg>
<svg class="svg">
<polygon fill="#f48fb1" points="104,145 24,126 17,43 94,12 147,75"/>
</svg>
<svg class="svg">
<polygon fill="#f48fb1" points="130,130 61,148 12,97 31,29 99,11 148,62"/>
</svg>
<svg class="svg">
<polygon fill="#f48fb1" points="131,135 85,117 45,144 48,96 10,66 57,54 74,9
100,49 148,51 117,88"/>
</svg>
</div>
line, polyline(선)
<div class="svgBox">
<svg class="svg">
<line x1="0" y1="0" x2="160" y2="160" stroke="#880e4f" stroke-width="2"/>
</svg>
<svg class="svg">
<line x1="80" y1="80" x2="160" y2="160" stroke="#880e4f" stroke-width="2"/>
</svg>
<svg class="svg">
<polyline fill="none" stroke="#880e4f" stroke-width="2"
points="21,20.667 21,143.333 140.333,24 140.333,143.333 28,20.667
28,143.333 "/>
</svg>
<svg class="svg">
<polyline fill="none" stroke="#880e4f" stroke-width="2"
points="19.667,22 132.333,22 24.667,138.333 132.333,138.333
22.333,28.333 132.333,28.333 "/>
</svg>
</div>
path(도형)
<div class="svgBox">
<svg class="svg">
<path fill="none" stroke="#880e4f" stroke-width="2" d="M7,154.667c0-82.358,65.152-149,145.667-149"/>
</svg>
<svg class="svg">
<path fill="none" stroke="#880e4f" stroke-width="2" d="M151.534,123.547c-33.711,33.711-88.369,33.711-122.08,0
c-26.97-26.969-26.97-70.695,0-97.665c21.575-21.576,56.556-21.576,78.131,0c17.261,17.26,17.261,45.245,0.001,62.504
c-13.809,13.809-36.196,13.809-50.005,0c-11.046-11.046-11.046-28.956,0-40.002c8.837-8.837,23.166-8.837,32.003,0
c7.069,7.07,7.07,18.532,0,25.602c-5.656,5.657-14.826,5.657-20.482,0c-4.524-4.524-4.524-11.86,0-16.385"/>
</svg>
<svg class="svg">
<path fill="none" stroke="#880e4f" stroke-width="2" d="M82.671,81.243c50.565,48.259,14.182,69.191-2.135,1.229
c16.316,67.962-25.611,65.895-2.46-0.122c-23.151,66.017-57.304,41.617-2.004-1.432c-55.3,43.049-70.84,4.057-0.912-2.288
c-69.929,6.345-61.919-34.86,0.47-2.417c-62.389-32.442-33.374-62.777,1.703-1.78c-35.076-60.997,5.73-70.826,2.395-0.577
c3.335-70.249,42.981-56.458,2.326,0.81c40.655-57.268,66.554-24.232,1.521,1.938c65.033-26.17,68.953,15.62,0.23,2.452
C152.526,92.225,133.236,129.502,82.671,81.243z"/>
</svg>
<svg class="svg">
<path fill="none" stroke="#880e4f" stroke-width="2" d="M131.502,129.683c-44.4-42.871-49.621-39.867-34.943,20.102
c-14.678-59.969-20.694-60.265-40.261-1.983c19.566-58.281,14.666-61.783-32.799-23.436C70.963,86.018,68.733,80.421,8.573,86.918
c60.16-6.497,61.31-12.409,7.692-39.569c53.617,27.16,57.781,22.808,27.864-29.131c29.917,51.938,35.772,50.527,39.189-9.441
c-3.417,59.969,2.272,61.948,38.075,13.245c-35.803,48.703-32.086,53.443,24.869,31.726C89.308,75.465,89.87,81.462,150.03,93.884
C89.87,81.462,87.102,86.812,131.502,129.683z"/>
</svg>
<svg class="svg">
<path fill="none" stroke="#880e4f" stroke-width="2" d="M58.665,139.312c0-6.873,42-6.873,42-13.747s-42-6.874-42-13.748
s42-6.874,42-13.748c0-6.872-42-6.872-42-13.744c0-6.874,42-6.874,42-13.747c0-6.877-42-6.877-42-13.753
c0-6.874,42-6.874,42-13.748c0-6.878-42-6.878-42-13.757s42-6.879,42-13.758"/>
</svg>
<svg class="svg">
<path fill="none" stroke="#880e4f" stroke-width="2" d="M93.108,91.478c42.049,30.58-13.048,57.425-13.347,6.503
c0.299,50.922-55.041,24.58-13.405-6.381c-41.636,30.961-55.545-28.728-3.37-14.458c-52.176-14.27-14.181-62.359,9.204-11.649
c-23.385-50.71,37.901-50.989,14.846-0.067c23.055-50.922,61.484-3.179,9.309,11.565C148.521,62.245,135.157,122.058,93.108,91.478
z"/>
</svg>
</div>
clip-path(클리핑 마스크)
SVG
SVG
SVG
<style>
.text-wrap {
background-color: #ffebee;
width: 160px; height: 160px;
display: inline-block;
}
.text-clip {
width: 160px; height: 160px;
line-height: 170px;
text-align: center; font-size: 70px;
font-family: "Black Han Sans";
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
background-image: url(../../assets/img/clip.jpg);
}
.text-clip.t2 {
background-image: linear-gradient(60deg, #ff5858 0%, #f09819 100%);
}
.text-clip3 {
background: #222;
width: 160px; height: 160px;
line-height: 170px;
text-align: center; font-size: 70px;
font-family: "Black Han Sans";
-webkit-text-fill-color: transparent;
-webkit-text-stroke: 3px #fff;
}
</style>
<div class="svgBox">
<svg class="svg">
<image xlink:href="../../assets/img/svg-french-fries.svg" width="160" height="160" />
</svg>
<svg class="svg">
<image xlink:href="../../assets/img/svg-french-fries.svg" width="160" height="160" clip-path="circle(40px at center)" />
</svg>
<svg class="svg">
<clipPath id="clip1">
<polygon fill="none" stroke="#000000" stroke-miterlimit="10" points="100.916,109.96 78.594,93.867 56.392,110.126 64.798,83.923
42.477,67.831 69.994,67.729 78.401,41.527 87,67.667 114.518,67.564 92.316,83.82 "/>
</clipPath>
<image xlink:href="../../assets/img/svg-french-fries.svg" width="160" height="160" clip-path="url(#clip1)" />
</svg>
<svg class="svg">
<clipPath id="clip2">
<path fill="none" stroke="#000000" stroke-miterlimit="10" d="M82.623,79.88c33.738,23.795,10.91,40.875-2.396,1.793
c13.307,39.082-15.199,39.483-2.992,0.042c-12.207,39.441-35.504,23.011-2.446-1.725c-33.059,24.736-42.248-2.254-0.965-2.833
c-41.283,0.579-32.854-26.656,0.885-2.859c-33.739-23.797-10.913-40.876,2.396-1.792c-13.31-39.084,15.198-39.484,2.993-0.042
c12.205-39.442,35.504-23.01,2.445,1.725c33.059-24.734,42.248,2.254,0.965,2.833C124.791,76.442,116.361,103.676,82.623,79.88z"/>
</clipPath>
<image xlink:href="../../assets/img/svg-french-fries.svg" width="160" height="160" clip-path="url(#clip2)" />
</svg>
<svg class="svg">
<text x="5" y="105" font-size="70" font-family="Black Han Sans" >SVG</text>
</svg>
<svg class="svg">
<pattern id="pattern1" patternUnites="useSpaceOnUse" width="100%" height="100%">
<image xlink:href="../../assets/img/clip.jpg" width="150" height="150" />
</pattern>
<text x="5" y="105" font-size="70" font-family="Black Han Sans" fill="url(#pattern1)">SVG</text>
</svg>
<br>
<div class="text-wrap">
<div class="text-clip">
SVG
</div>
</div>
<div class="text-wrap">
<div class="text-clip t2">
SVG
</div>
</div>
<div class="text-wrap">
<div class="text-clip3">
SVG
</div>
</div>
</div>
Animation
<style>
.aniRect1 {
stroke: #880e4f; stroke-width: 18;
transform-origin: center center;
animation: rect1 4s infinite linear;
}
@keyframes rect1 {
0% {stroke: #880e4f; stroke-width: 15; transform: rotate(0deg);}
35% {stroke: #311b92; stroke-width: 1; transform: rotate(360deg);}
70% {stroke: #004d40; stroke-width: 1; transform: rotate(360deg);}
100% {stroke: #880e4f; stroke-width: 15; transform: rotate(0deg);}
}
.aniRect2 {
stroke: #880e4f; stroke-width: 4;
animation: rect2 2s infinite ease-in-out alternate;
stroke-dasharray: 50;
stroke-dashoffset: 50;
stroke-linecap: round;
}
@keyframes rect2 {
0% {stroke: #880e4f; stroke-dashoffset: 50;}
35% {stroke: #311b92;}
70% {stroke: #004d40;}
100% {stroke: #880e4f; stroke-dashoffset: 0;}
}
.aniRect3 {
stroke: #880e4f; stroke-width: 4;
animation: rect3 4s infinite ease-in-out alternate;
stroke-dasharray: 100;
stroke-dashoffset: 100;
stroke-linecap: round;
}
@keyframes rect3 {
0% {stroke: #880e4f; stroke-dashoffset: 100;}
35% {stroke: #311b92;}
70% {stroke: #004d40;}
100% {stroke: #880e4f; stroke-dashoffset: 0;}
}
.aniRect4 {
stroke: #880e4f; stroke-width: 4;
animation: rect4 4s infinite linear;
stroke-dasharray: 400;
stroke-dashoffset: 400;
stroke-linecap: round;
}
@keyframes rect4 {
0% {stroke: #880e4f; stroke-dashoffset: 400;}
35% {stroke: #311b92;}
70% {stroke: #004d40;}
100% {stroke: #880e4f; stroke-dashoffset: 0;}
}
.aniPath1 {
fill: #ff0000; stroke: #000; stroke-width: 3;
stroke-linecap: round;
animation: path1 3s infinite linear alternate-reverse;
stroke-dasharray: 800;
}
@keyframes path1 {
0% {stroke-dashoffset: 800;}
100% {stroke-dashoffset: 0;}
}
.aniPath2 {
fill: none; stroke: #880e4f; stroke-width: 2;
animation: path2 2s infinite linear alternate-reverse;
stroke-dasharray: 1090;
}
@keyframes path2 {
0% {stroke-dashoffset: 1090;}
100% {stroke-dashoffset: 0;}
}
.aniPath3 {
fill: none; stroke: #880e4f; stroke-width: 2;
animation: path2 4s infinite linear alternate-reverse;
stroke-dasharray: 412;
}
@keyframes path3 {
0% {stroke-dashoffset: 412;}
100% {stroke-dashoffset: 0;}
}
.aniPath4 {
fill: none; stroke: #880e4f; stroke-width: 2;
animation: path2 4s infinite linear alternate-reverse;
stroke-dasharray: 1178;
}
@keyframes path4 {
0% {stroke-dashoffset: 1178;}
100% {stroke-dashoffset: 0;}
}
</style>
SVG - Text Animation1
See the Pen SVG - Text Animation1 by 김용태 (@sdw6545) on CodePen.
SVG - Text Animation2
See the Pen SVG - Text Animation2 by 김용태 (@sdw6545) on CodePen.
SVG - Text Animation3
See the Pen SVG - Text Animation3 by 김용태 (@sdw6545) on CodePen.