very new here so I'm sure I'm missing something obvious but I would like an HTML button that opens a users native email client with the To: field prepopulated.
<form>
<button action="mailto:[email protected]" type="submit"> Contact</button>
</form>
Here is the accompanying CSS:
.button-21 {
align-items: center;
appearance: none;
background-color: #3eb2fd;
background-image: linear-gradient(1deg, #4f58fd, #149bf3 99%);
background-size: calc(100% 20px) calc(100% 20px);
border-radius: 100px;
border-width: 0;
box-shadow: none;
box-sizing: border-box;
color: #ffffff;
cursor: pointer;
display: inline-flex;
font-family: CircularStd, sans-serif;
font-size: 1rem;
height: auto;
justify-content: center;
line-height: 1.5;
padding: 6px 20px;
position: relative;
text-align: center;
text-decoration: none;
transition: background-color 0.2s, background-position 0.2s;
user-select: none;
-webkit-user-select: none;
touch-action: manipulation;
vertical-align: top;
white-space: nowrap;
}
.button-21:active,
.button-21:focus {
outline: none;
}
.button-21:hover {
background-position: -20px -20px;
}
.button-21:focus:not(:active) {
box-shadow: rgba(40, 170, 255, 0.25) 0 0 0 0.125em;
CodePudding user response:
action is a form's attribute for submission. You should move the action attribute from the button to the form.
.button-21 {
align-items: center;
appearance: none;
background-color: #3eb2fd;
background-image: linear-gradient(1deg, #4f58fd, #149bf3 99%);
background-size: calc(100% 20px) calc(100% 20px);
border-radius: 100px;
border-width: 0;
box-shadow: none;
box-sizing: border-box;
color: #ffffff;
cursor: pointer;
display: inline-flex;
font-family: CircularStd, sans-serif;
font-size: 1rem;
height: auto;
justify-content: center;
line-height: 1.5;
padding: 6px 20px;
position: relative;
text-align: center;
text-decoration: none;
transition: background-color 0.2s, background-position 0.2s;
user-select: none;
-webkit-user-select: none;
touch-action: manipulation;
vertical-align: top;
white-space: nowrap;
}
.button-21:active,
.button-21:focus {
outline: none;
}
.button-21:hover {
background-position: -20px -20px;
}
.button-21:focus:not(:active) {
box-shadow: rgba(40, 170, 255, 0.25) 0 0 0 0.125em;
}
<form action="mailto:[email protected]">
<button type="submit">Contact</button>
</form>
CodePudding user response:
Try this :)
<form>
<button onclick="location.href='mailto:[email protected]';" type="button"> Contact</button>
</form>
CodePudding user response:
As well as a button inside a form, you can also use a link for this:
<a href="mailto:[email protected]">Contact</a>
CodePudding user response:
<form action="mailto:[email protected]">
<button type="submit"> Contact</button>
</form>