
442 P.2d 788 (1968)
79 N.M. 298
Osie ROBERTS and Stella Roberts, his wife, Petitioners-Appellants,
v.
Donald STAPLES, Respondent-Appellee.
No. 8529.
Supreme Court of New Mexico.
July 1, 1968.
*789 Jack Underwood, Lovington, Perry O. Barber, Sr., Colorado City, Tex., for petitioners-appellants.
Albert J. Rivera, Alamogordo, for respondent-appellee.

OPINION
ARMIJO, Judge, Court of Appeals.
The maternal grandparents (appellants) by writ of habeas corpus sought to obtain custody of their four year old granddaughter from her father, appellee herein. Following trial, the court rendered its decision resolving the issues in favor of appellee and this appeal follows entry of judgment dismissing the petition.
The following facts are undisputed: by decree entered March 9, 1965, in divorce action, filed in Otero County District Court, as cause number 10448, the custody of the child was awarded to the mother, subject to visitation privileges in the father, which he exercised from time to time. After the divorce both parents remarried other spouses. On May 23, 1966, the mother died following a motor vehicle collision in New Mexico.
Appellants arranged for their daughter's funeral in Texas where they resided and took their granddaughter with them at their daughter's request made shortly before her death.
The day following the accident, appellee applied for and was granted an ex parte order in the divorce case, placing custody of the child with him.
Appellants returned to New Mexico with the child, approximately three weeks after the accident at which time the child was delivered to appellee pursuant to the order issued in the divorce case.
Thereafter, the child remained with appellee, and appellants visited her regularly until October when relations between the parties became strained and resulted in appellee notifying appellants by letter, dated November 3, 1966, that subsequent visits with the child were forbidden. The petition for a writ of habeas corpus was filed five months later and followed the filing of proceedings by appellee's present wife to adopt the child.
Appellants seek reversal on several grounds and ask to have the child's custody restored to them or that they may be granted a new trial. None of these contentions are considered sufficiently persuasive to warrant disturbing the trial court's ruling.
In this case, appellants base their claim for custody on their love and affection for the child; the fact they had the child in their possession following the death of *790 their daughter in accord with decedent's wishes; their fitness; ability and willingness to care and provide for her support and needs and generally, that it would be in her best interest and welfare to have her custody restored to them.
Other allegations are made concerning appellee's unfitness to have the care, custody and control of his child, and that he has alienated the child against appellants after having obtained custody by virtue of a void ex parte order.
Because of our holding with respect to matters of pleading and proof concerning appellants' legal right to custody, which compels affirmance of the trial court's judgment, a lengthy discussion of the claimed errors becomes unnecessary.
The writ of habeas corpus finds its origin in common law. It issues as a matter of right and not as a matter of course. When prosecuted as a means of determining custodial rights of children, however, the inquiry is generally broader than that normally involved in habeas corpus. The child's welfare becomes a prime consideration irrespective of the parties' interests, although the natural rights of parents, guardians or lawful claimants are entitled to due consideration. See Annot. at 4 A.L.R. 3rd, 1277, 1282 (1965).
It is fundamental that under appropriate circumstances, habeas corpus is an available remedy by which to consider controversies involving the issue of custody of infants. Lopez v. Smith, 146 Colo. 180, 360 P.2d 967 (1961). This remedy has been recognized in this jurisdiction since early times. Bustamento v. Analla, 1 N.M. 255 (1857). See also Bassett v. Bassett, 56 N.M. 739, 250 P.2d 487 (1952) and Focks v. Munger, 20 N.M. 335, 149 P. 300, L.R.A. 1915E, 1019 (1915).
The question of a grandparent's legal right to apply for writ of habeas corpus when the issue of custody of infants is involved, has not heretofore been considered by us. We consider if appellants possess the right necessary to obtain the issuance of a writ of habeas corpus.
In cases dealing with infants, it is uniformly held that a writ of habeas corpus will be granted only in those cases where the applicant shows a prima facie legal right to the custody of the child. See 1 Bailey on Habeas Corpus § 148 (1st ed. 1913). In re Stuart, 138 Wash. 59, 244 P. 116 (1926); In re Lorok, 93 Ohio App. 251, 114 N.E.2d 65 (1952); Wilcox v. Fisher, 163 Kan. 74, 180 P.2d 283 (1947). In re Stuart, supra, further held the grandparents of a child have no natural or inherent right to its custody. In this we agree.
We think appellants' allegation of former custody of the child is insufficient to establish a prima facie right. The custody they had assumed in accordance with the wishes of their deceased daughter was not based on a right born of a court order. Compare State ex rel. Hockenhull v. Marshall, 58 N.M. 286, 270 P.2d 702 (1954). Thus appellants have not been deprived of custody which they could claim as a matter of right. See Lopez v. Smith, supra.
On the question of existence of a legal right to maintain the action to obtain custody of infants by writ of habeas corpus, we quote with approval from Thomas v. Sprinkle, 299 Ky. 839, 187 S.W.2d 738 (1945):
"It is unnecessary to discuss the testimony since the failure of appellant to allege or prove a prima facie legal right to the infants' custody necessitates an affirmance of the judgment. Either parent, the next of kin, or one standing in loco parentis to the infant may maintain such an action against one having a lesser right to the child's custody, the degree of which right is usually measured by the child's welfare as distinguished from priority or superiority of legal commitments. It may be maintained even though the infant is not actually restrained of his liberty and is merely residing with the custodian of his choice. *791 But, though technical requirements incident to the obtention of the writ have generally been disregarded where the actual question involved was the custody and welfare of the infant, we know of no case in which it has been held that the writ may be obtained by one devoid of legal or natural right against a parent whose superior natural right of custody has not been legally terminated or voluntarily surrendered. 25 Amer.Juris., Secs. 79, 80, Pages 204, 205, 206."
In State ex rel. White v. Swink, 241 Mo. App. 1048, 256 S.W.2d 825 (1953), the right of the grandparents to obtain issuance of a writ of habeas corpus for the return of custody of their grandchild who prior thereto had been with them for several years, was questioned by the parents against whom the writ was issued. It was held:
"The right of the parents to the custody of their minor children is not an absolute right that will be granted to them under any and all circumstances, as will be observed from the above mentioned authorities. It may be denied if there is a showing that the parents are unfit for the trust. However, there is nothing in this statement of the law that would authorize one who has no legal right to the custody of a minor child to bring an action in habeas corpus for custody. The one bringing the action must either be entitled to the custody of the child or have been duly authorized in some manner by the child detained to bring the action. The petitioner must stand in the position of parent, guardian, or some one entitled to custody by reason of some court order or judgment. If he does not occupy the position of one of the aforesaid parties he has no right to bring the action."
The court further held that since petitioners had no legal right to bring the action for the custody of the child that there was no jurisdiction to make findings with respect to neglect or to abandonment of the child and award custody.
In habeas corpus proceedings, the movant has the burden of showing that he is entitled to the writ and the writ should be denied where the allegations are insufficient. See 39 C.J.S. Habeas Corpus § 82 (1944).
Unquestionably, the order issued in the divorce case after the death of the mother and attempting to grant appellee custody of the child was null and void. Involved in State ex rel. Hockenhull v. Marshall, supra, was an issue of whether upon the death of the mother, who was the custodial parent following divorce, the custody of the child reverted automatically to the father. This question was answered in the negative. This holding however does not support a view that a surviving parent is stripped of all custodial rights. Following the death of the child's mother, appellee obtained a void court order placing the right to custody in him. This fact, however, does not create a right in the appellants who voluntarily delivered possession pursuant to the order to thereafter have the issue of the best interest and welfare of the child litigated on a petition for a writ of habeas corpus. Parents have a natural and legal right to custody of their children. This right is prima facie and not an absolute right. Cook v. Brownlee, 54 N.M. 227, 220 P.2d 378 (1950); Pra v. Gherardini, 34 N.M. 587, 286 P. 828 (1930); Allen v. Huffman, 135 Colo. 1, 307 P.2d 802 (1957) and Moss v. Vest, 74 Idaho, 328, 262 P.2d 116 (1953). This right however must yield when the best interests and welfare of the child are at issue. Allen v. Huffman, supra; Schreifels v. Schreifels, 47 Wash.2d 409, 287 P.2d 1001 (1955).
Placing of custody of the child with her mother in cause 10448, did not have the effect of extinguishing appellee's natural right to custody nor of adversely determining the issue of his fitness.
We are not here concerned with the issue of whether the right to custody of a child following the death of the custodial parent automatically passes to the surviving parent, but rather with the standing to *792 maintain an action against a parent who has a child in custody by one who has no legal standing to do so.
We do not overlook the issue sought to be determined with regard to the best interests and welfare of the child, which incidentally, the trial court after due consideration resolved in appellee's favor, but we conclude that it was incumbent on appellants to establish a prima facie legal right to custody of the child of which they had been deprived or that they had a natural or legal right upon which to base their claim and since they failed to plead and prove such a premise, the trial court ruled correctly in dismissing the action.
The judgment is affirmed.
It is so ordered.
NOBLE and MOISE, JJ., concur.
